见下面的代码:
Collection:
[
{
_id: 'abc',
UserName: 'aaaa',
Password: 'xxxx',
Friends:
[
{
FriendId: 'bbb',
Confirm: 1
},
{
FriendId: 'ccc'
Confirm: 0
}
]
},
{
_id: 'cdk',
UserName: 'bbbbbbbb',
Password: 'xxxxzz',
Friends:
[
{
FriendId: 'bbb',
Confirm: 1
},
{
FriendId: 'aaa'
Confirm: 0
}
]
}
]
我想在{ Friend: 'ddd', Confirm: 0 }
中添加item _id: 'abc'
。
答案 0 :(得分:0)
您需要$push
- 运营商:
db.collection.update( { "_id": "abc" }, { $push: { Friends: { Friend: 'ddd, Confirm: 0 } } } );