如果你能看一下下面
documentation
,您可能会认识到,对于keyconditionexpressions,只有以下运算符有效:
EQ | LE | LT | GE | GT | BEGINS_WITH | BETWEEN
所以,这里是交易-如果你想继续使用dynamodb,并且想做一些像
IN
对于关键条件表达式,您必须向dynamodb发送各种请求,每次都要单独包含一个作者,然后在您的末尾将它们组合在一起。
像这样:
// Considering that this docClient is the instance of aws-sdk configured for dynamodb
const TABLE = 'Videos';
const createParams = (author) => {
return {
TableName: TABLE,
KeyConditionExpression: "author = :author",
ExpressionAttributeValues: {
":author": author
}
};
}
const queryPromise = (params) => {
return new Promise((resolve, reject) => {
docClient.query(params, function (err, data) {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
// The list of authors
const authors = ['Vauxhall', 'Piccadilly', 'Acton', 'Milton', 'Hempsworth'];
const promises = [];
authors.forEach((author) => {
promises.push(queryPromise(createParams(author)));
});
Promise.all(promises).then(results => {
// Do your stuff here
}).catch(error => {
// Handle errors the way you would
});