我使用Dynamoose来简化在 Node.js 应用程序中与 DynamoDB 的交互。我正在尝试使用 Dynamoose 的 Model.query 函数编写一个查询,该函数将使用索引搜索表,但 Dynamoose 似乎不包含处理查询所需的所有信息,我不确定我在做什么做错事。
该架构如下所示:
const UserSchema = new dynamoose.Schema({
"user_id": {
"hashKey": true,
"type": String
},
"email": {
"type": String,
"index": {
"global": true,
"name": "email-index"
}
},
"first_name": {
"type": String,
"index": {
"global": true,
"name": "first_name-index"
}
},
"last_name": {
"type": String,
"index": {
"global": true,
"name": "last_name-index"
}
}
)
module.exports = dynamoose.model(config.usersTable, UserSchema)
Run Code Online (Sandbox Code Playgroud)
我希望能够通过电子邮件地址搜索用户,因此我编写了一个如下所示的查询:
Users.query("email").contains(query.email)
.using("email-index")
.all()
.exec()
.then( results => {
res.status(200).json(results)
}).catch( err => …Run Code Online (Sandbox Code Playgroud)