Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda