node.js - 如何使用 NodeJS 和条件表达式访问 DynamoDB 中的嵌套元素?
问题描述
我在尝试使用条件表达式访问嵌套在 DynamoDB 表中的元素时遇到问题。我正在尝试的代码如下:
const params = {
TableName: 'Games',
Key: {
id: gameID.id,
},
UpdateExpression: 'SET #players = list_append(#answers , :answer)',
ConditionExpression: '#players CONTAINS :playerID',
ExpressionAttributeNames: {
'#players': 'Players',
'#answers': 'answers',
},
ExpressionAttributeValues: {
':playerID': userID.id,
':answer': tempAnswerList,
},
ReturnValues: 'ALL_NEW',
例如,此版本引发错误:
Invalid ConditionExpression: Syntax error; token: "CONTAINS", near: "#players CONTAINS :playerID"
有没有办法在不知道它的 id 的情况下查看数组?就像我在#players 上寻找要使用的通配符一样,因为它是一个列表,但我在文档中看不到。
谢谢,马克
解决方案
请按contains
如下所述更改并尝试。
ConditionExpression: 'contains (#players, :playerID)',
推荐阅读
- apache-flink - PyFlink UDF:何时使用矢量化与标量
- angular - 将 ui_locales 传递给 Msal Angular Guard
- php - {"code":29000,"message":"签名不匹配"}
- android-drawable - 弯曲带有高度的圆形可绘制矩形
- javascript - 在类上使用对象字面量会浪费多少内存?
- unix - 如何检查用户输入是否等于文件中的值?
- typescript - 属性可以是字符串或对象数组,如何在 VS Code 中告诉打字稿当前变量正在使用数组
- sql - 在 SQL Server 16 的 sql 查询中拆分超过 4 个值的字符串值
- lighthouse - Lighthouse 修改 HTML 报告 - 添加截图
- electron - 在 Electron 应用程序中保存数据结构的最佳方法