给出的是一个包含书籍对象的数组,其中每个状态
都必须更新:
var books = [
{ id: '58b2e58', status: 'pending' },
{ id: '5903703', status: 'pending' }
]
var status = {status: 'accepted'}
我试过this :
Book.update(books, status).exec(function afterwards(err, updatedbooks) {
if (err) {
res.json(err)
}
console.log("updatedbooks:", updatedbooks);
});
但“updatedbooks”日志为空。在 mongodb 中检查时,书籍就在那里,我可以使用 Book.find(books);
如here mentioned这在这里工作得很好,但我想在 WHERE 标准中除了 ID 之外还有 status==“pending”。
最佳答案
请尝试一下。
var bookId= ['1','3'];
var status = {status: 'accepted'}
Book.update({id:bookId, status: 'pending'}, status).exec(function afterwards(err, updatedbooks) {
if (err) {
console.log('error in update\n'+err);
res.json(err)
}
else{
console.log("updatedbooks:", updatedbooks);
}
});
这应该有效。另外,如果您遇到错误,它会让您了解所遇到的错误。
关于node.js - 在 Mongodb 上使用 Waterline 更新模型中的多个记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43686649/