[英]Dynamo db query using contains operator
My table items are of the form of 我的表项目的形式
function addDoc(movie,cb){
var params = {
TableName: "Movies",
Item: {
"year": movie.year,
"title": movie.title,
"info": movie.info,
"genres" : movie.info.genres || []
}
};
docClient.put(params, function(err, data) {
bar.tick(1)
i++;
cb(err);
});
}
async.eachLimit(allMovies,50,addDoc,function (err) {
console.log(err)
console.log("done inserting " + i + " movies");
});
I'm running this code : 我正在运行此代码:
var params = {
TableName : "Movies",
//ProjectionExpression:"#yr, title, genres, info.actors[0]",
KeyConditionExpression: "#yr = :yyyy and contains(genres, :g1)",
ExpressionAttributeNames:{
"#yr": "year"
},
ExpressionAttributeValues: {
":yyyy":1992,
":g1" : "Drama"
},
//Select : "COUNT"
};
var start = Date.now()
docClient.query(params, function(err, data) {
if (err) {
console.error("Unable to query. Error:", JSON.stringify(err, null, 2));
} else {
console.log("time elapsed :",Date.now()-start);
console.log("Query succeeded.");
console.log(data)
}
});
and I'm getting this error 而且我收到了这个错误
"Invalid operator used in KeyConditionExpression: contains"
“KeyConditionExpression中使用的运算符无效:包含”
any idea? 任何想法?
There are few things that need to be clarified here. 这里有一些事情需要澄清。
1) The Key attributes of DynamoDB has to be scalar data type. 1)DynamoDB的Key属性必须是标量数据类型。 So, I believe the attribute
genres
can't be defined as SET or LIST data type 所以,我认为属性
genres
不能定义为SET或LIST数据类型
2) KeyConditionExpression
- can refer to Hash and Sort key only. 2)
KeyConditionExpression
- 只能引用哈希和排序键。 So, I presume the attribute genres
is defined as SORT key of the table 所以,我假设属性
genres
被定义为表的SORT键
3) contains
can be used on FilterExpression
on data types STRING, SET or LIST. 3)
contains
可用于FilterExpression
的数据类型STRING,SET或LIST。 It can't be used on KeyConditionExpression
它不能用于
KeyConditionExpression
Conclusion - Refer point 3 for straight forward answer 结论 - 参考第3点直接回答
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.