Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
Inserting a map item into DynamoDb

I have a table which is indexed by player accounts, and each player account has an empty map called "games." Whenever a new game is created, I'd like to insert a new item into that map for the new game, with some starting values. However this Javascript code below gives me an error:

            let newGame = {
                "live": { "BOOL": true },
                "result": { "S": "in_progress" }
            };

            let params = {
                TableName: "games_roster",
                Key: { "account_id" : playerAccount },
                UpdateExpression: "SET games.#game_id = :new_game",
                ExpressionAttributeNames: {
                    "#game_id": {"S": gameId}
                },
                ExpressionAttributeValues: {
                    ":new_game": {"M": newGame}
                }
            };

            await dynamoClient.send(new UpdateItemCommand(params));

The error:

TypeError: Cannot read properties of undefined (reading '0')
    at Object.AttributeValue.visit (models_0.js?31ed:996:1)
    at serializeAws_json1_0AttributeValue (Aws_json1_0.js?1450:4056:1)
    at eval (Aws_json1_0.js?1450:4484:1)
    at Array.reduce (<anonymous>)
    at serializeAws_json1_0Key (Aws_json1_0.js?1450:4478:1)
    at serializeAws_json1_0UpdateItemInput (Aws_json1_0.js?1450:5112:1)
    at eval (Aws_json1_0.js?1450:520:1)
    at step (tslib.es6.js?9ab4:102:1)
    at Object.eval [as next] (tslib.es6.js?9ab4:83:1)
    at eval (tslib.es6.js?9ab4:76:1)

I've verified that none of the variables are undefined by logging out the params object, so where would I be getting an TypeError?

Owing to @fedanov's answer, this is the correct format:

            let newGame = {
                live: { BOOL: true },
                result: { S: "in_progress" }
            };

            let params = {
                TableName: "games_roster",
                Key: { "account_id" : { S: playerAccount } },
                UpdateExpression: "SET games.#game_id = :new_game",
                ExpressionAttributeNames: {
                    "#game_id": gameId
                },
                ExpressionAttributeValues: {
                    ":new_game": { M: newGame }
                }
            };

            await dynamoClient.send(new UpdateItemCommand(params));
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are passing the wrong types to UpdateItemCommandInput. The Key parameter expects DynamoDB JSON values, ExpressionAttributeNames string values:

Key: { account_id: { S: playerAccount} },
ExpressionAttributeNames: { "#game_id" : gameId }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda