我在MongoDB中有以下格式的记录:
{
attachment: 'xxxxxxx',
createdAt: TueAug04201514: 52: 23GMT+0400(GST),
text: 'xxxxxxx',
sender: '55784247c95c59cc746904e1',
status: [
{
user: '5589464675fc0892757d170e',
is_read: 0
},
{
user: '55a4a39d5c0bf23d21e6c485',
is_read: 0
},
{
user: '55a4a38e5c0bf23d21e6c483',
is_read: 0
},
{
is_read: 0,
user: '55784247c95c59cc746904e1'
}
],
thread: '55c0946b80320adb3fd04d0e',
updatedAt: TueAug04201515: 45: 55GMT+0400(GST),
id: '55c09967708b73184558fbc8'
}
我想更新
status
数组内的is_read
。以下是我的尝试。 Messages.update({
thread: threadIds,
status: { $elemMatch: { user: user.id, is_read: 0 } }
},
{ $set: { "status.$.is_read": 1 } })
但是相同的查询在mongodb shell中运行得非常好。有人能指导我是否遗漏了什么吗?顺便说一下,我正在SailsJS中运行此查询,它使用Waterline ORM。
Message
模型和其status
属性之间有什么关系? - Yann Bertrand