如何使用DynamoDB中的IN条件查询表
努力寻找一个如何查询表的例子,以返回给定列表中的id。
下面的查询将引发IN的包含
var params = { id: '7deb3df9-552b-47a4-aef3-ad601f141d50' }; var p = { TableName: 'players', KeyConditionExpression: 'id IN (:id)', ExpressionAttributeValues: buildQuery(params) };
你不能在KeyConditionExpression中使用“IN”运算符,请看这个SO问题的细节
您可能想要使用batchGetItem而不是查询,尽pipe这不是很有效。
下面是你的参数可能是这样的:
var params = { RequestItems: { 'players': { Keys: [{ id: "7deb3df9-552b-47a4-aef3-ad601f141d50", rangeKey: "<range key 1>" // <--- if your table has a range key, you must specify its value here }, { id: "<ANOTHER ID 2>", rangeKey: "<range key 2>" }, { id: "<ANOTHER ID 3>", rangeKey: "<range key 3>" }] } } }; dynamodbDoc.batchGet(params, function(err, data) { });