无法检索Nodejs查询的记录。数据(JSON格式)与代码一起在下面给出。我的数据包含嵌套属性,这使查询查询变得困难。尽管Nodjs查询有效,但是您无法获得数据结果。
[
{
"department": 1,
"city": "city01",
"info": {
"markets": [
{
"name": "marché de city01",
"day": "vendredi matin",
"location": "place de la république",
"frequence": "hebdomadaire",
"category": "tous produits",
"merchants": "40",
"link": "https://www.city01.html"
}
]
}
},
{
"department": 2,
"city": "city02",
"info": {
"markets": [
{
"name": "marché de city02",
"day": "samedi matin",
"location": "place de la liberté",
"frequence": "hebdomadaire",
"category": "tous produits",
"merchants": "80",
"link": "https://www.city02.html"
},
{
"name": "marché de city02",
"day": "lundi après-midi",
"location": "place de la mairie",
"frequence": "bi-mensuel",
"category": "tous produits",
"merchants": "60",
"link": "https://www.city02.html"
}
]
}
}
]
var AWS = require("aws-sdk");
AWS.config.update({
region: "eu-west-1"
});
var docClient = new AWS.DynamoDB.DocumentClient();
// recherche par contenu
console.log("Querying for markets of 1 (Ain) for city equal: city01");
var params = {
TableName : "TestMarkets",
ProjectionExpression:"#dep, #city, #info",
KeyConditionExpression: "#dep = :dep and #city = :city",
FilterExpression: "contains (#market, :ddd)",
ExpressionAttributeNames:{
"#dep": "department",
"#info": "info",
"#city": "city",
"#market": "info.markets"
},
ExpressionAttributeValues:{
":dep": 1,
":ddd": {
"day": "vendredi matin"
},
":city": "city01",
}
};
docClient.query(params, function(err, data) {
if (err) {
console.log("Unable to query. Error:", JSON.stringify(err, null, 2));
} else {
console.log("Query succeeded.");
console.log(JSON.stringify(data));
data.Items.forEach(function(item) {
console.log("Dep: ", item.department + ", City: " + item.city);
console.log(JSON.stringify(item.info));
});
}
});
为什么结果没有任何项目?谢谢。
答案 0 :(得分:0)
对于初学者来说,查询中的ExpressionAttributeValues
的值无效。
ExpressionAttributeValues: {
":dep": {
N: "1"
},
":ddd": {
M: {
"day": {
S: "vendredi matin"
}
}
},
":city": {
S: "city01"
}
}
答案 1 :(得分:0)
感谢您的回复。通过以下更改,我出现以下错误。
Querying for markets of 1 (Ain) for city equal: city01
Unable to query. Error: {
"message": "One or more parameter values were invalid: Condition parameter
type does not match schema type",
"code": "ValidationException",
"time": "2019-04-01T14:49:55.756Z",
"requestId": "DIQOM6P7U18JSE9U3UEE5VNNNFVV4KQNSO5AEMVJF66Q9ASUAAJG",
"statusCode": 400,
"retryable": false,
"retryDelay": 12.377875615412904
}
在Node.js代码中仅“ ExpressionAttributeValues”部分已更改(如上所述)。
ExpressionAttributeValues: {
":dep": {
"N": 1
},
":ddd": {
"M": {
"day": {
"S": "vendredi matin"
}
}
},
":city": {
"S": "city01"
}
}