我正在使用 Dynamodb 和 Nodejs 开发一个项目。我需要一个针对多个字段(例如select * from table where name=this and age=22 and active=this and area=this. 我需要一个不允许我仅查询扫描的解决方案。如果可能的话,请通过示例 Nodejs 脚本告诉我。
这是代码。
1)更改表名
2) 如果您使用 AWS DynamoDB 服务,请更改登录凭证。以下代码使用本地 DynamoDB 服务
var AWS = require("aws-sdk");
var creds = new AWS.Credentials('akid', 'secret', 'session');
AWS.config.update({
region : "us-west-2",
endpoint : "http://localhost:8000",
credentials : creds
});
var docClient = new AWS.DynamoDB.DocumentClient();
var table = "tablename";
var params = {
TableName : table,
KeyConditionExpression : 'personId = :personIdval',
FilterExpression : '#name= :nameVal and age= :ageVal and active=:activeVal and area=:areaVal',
ExpressionAttributeNames : {
'#name' : 'name'
},
ExpressionAttributeValues : {
':personIdval' : '7',
':nameVal' : 'this',
':ageVal' : 22,
':activeVal' : 'this',
':areaVal' : 'this'
}
};
docClient.query(params, function(err, data) {
if (err) {
console.error("Unable to read item. Error JSON:", JSON.stringify(err,
null, 2));
} else {
console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4950 次 |
| 最近记录: |