mongodb 中的嵌套数组更新
我有一个集合,其结构是:-
I have collection the structure of which is :-
Subscribed.insert({
"name": "Manager1",
"emailId": "arora.priya4172@gmail.com",
"category": "Finance",
"designation": 'Head',
"done": false,
"categorySubscribedUsers": [
{
"_id": "u4._id",
"username": "u4.profile.name",
"issuesNotToDisplay": []
},
{
"_id": "u4._id",
"username": "u4.profile.name",
"issuesNotToDisplay": []
},
{
"_id": "u4._id",
"username": "u4.profile.name",
"issuesNotToDisplay": []
}
]
});
我想在 issuesNotToDisplay 字段中插入一个字段.因此,为此我使用以下命令但出现错误:
I want to insert a field in issuesNotToDisplay field. So, for this I am using the following command but getting error:
'syntax error: missing : after property id' in browser console 和'syntax error missing token .'
'syntax error: missing : after property id' in browser console and 'syntax error missing token .'
在 mongodb 控制台中.
In the mongodb console.
谁能告诉我在 mongodb 中更新双重嵌套数组中的字段的正确命令应该是什么.我尝试了很多,也读过书,但仍然一无所知.为什么这个命令会报错?
Can anyone please tell me what should be the proper command for updating a field in doubly nested array in mongodb. I have tried a lot and read book too but still clueless. Why this command is giving error?
命令是:-
db.subscribed.update(
{
"category": "Finance",
"categorySubscribedUsers": "priya"
},
{
"$addToSet": {
"categorySubscribedUsers.$.issueNotToDisplay": "25PEgZoMamLSTDdw7"
}
}
);
也许你需要这个
db.subscribed.update(
{
"category": "Finance",
"categorySubscribedUsers.username" : "u4.profile.name"
},
{
"$addToSet": {
"categorySubscribedUsers.$.issueNotToDisplay": "25PEgZoMamLSTDdw7"
}
}
)