我正在创建一个聊天应用程序并使用 Dynamoose.js。我有一张conversations
桌子和一张messages
桌子。我想在messages
表上查询以查找属于对话的所有消息。当我进行查询时,我收到以下错误:
message: 'Invalid operator used in KeyConditionExpression: IN',
code: 'ValidationException',
这是我的模式和查询的样子:
对话.model.js
let schema = {
conversation_id: {
hashKey: true,
type: String,
required: true
},
participants: {
type: Array,
schema: [String],
required: true
},
lastModified: {
type: Date,
required: true,
default: Date.now
}
};
消息模型.js
let schema = {
message_id: {
hashKey: true,
type: String,
required: true,
index: {
name: 'conversationIndex',
global: true,
rangeKey: 'conversation_id',
throughput: {'read': 10, 'write': 10}
}
},
conversation_id: {
rangeKey: true,
type: String,
required: true
},
from: {
type: String,
required: true
},
message: {
type: String,
required: true
},
ts: {
type: Date,
required: true,
default: Date.now
}
询问
Message.query('conversation_id').in(userConversations).using('conversationIndex').exec((err, messages) => {
// userConversations is an array of conversation_id's
if (err) {
console.error(err);
} else {
}
});
知道我要去哪里错了吗?我认为这可能与我创建和使用二级索引的方式有关,但我不太确定。任何帮助表示赞赏,谢谢!