Node.js 关于查询DynamoDB的困惑
我的DynamoDB中有以下数据 我正在努力实现以下结果。 扫描表格并获取Node.js 关于查询DynamoDB的困惑,node.js,amazon-dynamodb,Node.js,Amazon Dynamodb,我的DynamoDB中有以下数据 我正在努力实现以下结果。 扫描表格并获取管理为空且位置为Midwest的行 我最初尝试下面的查询来匹配Null var scanningParameters = { TableName: 'LOB', FilterExpression: "#mgmt contains NULL", ExpressionAttributeNames: { "#mgmt": "Management", } }; docClient
管理为空且位置为Midwest
的行
我最初尝试下面的查询来匹配Null
var scanningParameters = {
TableName: 'LOB',
FilterExpression: "#mgmt contains NULL",
ExpressionAttributeNames: {
"#mgmt": "Management",
}
};
docClient.scan(scanningParameters, onScan);
function onScan(err, data) {
if (err) {
console.error("Unable to scan the table. Error JSON:", JSON.stringify(err, null, 2));
} else {
// print all the movies
console.log("Scan succeeded.");
data.Items.forEach(function (data) {
console.log(
data.lineofbusiness + " name : ",
data.name);
});
if (typeof data.LastEvaluatedKey != "undefined") {
console.log("Scanning for more...");
scanningParameters.ExclusiveStartKey = data.LastEvaluatedKey;
docClient.scan(scanningParameters, onScan);
}
}
}
我得到的例外是
{
"message": "Invalid FilterExpression: Syntax error; token: \"contains\", near: \"#mgmtcontains NULL\"",
"code": "ValidationException",
"time": "2017-05-03T13:21:11.611Z",
"requestId": "0T0GU59HRJ24P96D42H9QNC97RVV4KQNSO5AEMVJF66Q9ASUAAJG",
"statusCode": 400,
"retryable": false,
"retryDelay": 13.73953651636839
}
请让我知道哪里出了问题,以及如何解决此问题。这里是对“NULL”值(即字符串属性的数据为NULL)的扫描项 我假设管理属性是包含字符串值“NULL”的字符串数据类型 代码:-
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 params = {
TableName: "lob",
FilterExpression: "#mgmt = :mgmtVal",
ExpressionAttributeNames: {
"#mgmt": "Management",
},
ExpressionAttributeValues : {
":mgmtVal" : "NULL"
}
};
docClient.scan(params, onScan);
var count = 0;
function onScan(err, data) {
if (err) {
console.error("Unable to scan the table. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("Scan succeeded.");
data.Items.forEach(function(itemData) {
console.log("Item :", ++count,JSON.stringify(itemData));
});
if (typeof data.LastEvaluatedKey != "undefined") {
params.ExclusiveStartKey = data.LastEvaluatedKey;
docClient.scan(params, onScan);
}
}
}
我假设您在管理属性上的值为NULL。如果管理属性中的值为NULL,即使扫描到“是”足够好,我也可以得到rest@notionquest我不擅长NoSql,我的经验是SQL,这就是为什么我很困惑的原因