mongodb 中的嵌套数组更新

编程入门 行业动态 更新时间:2024-10-28 03:33:17
本文介绍了mongodb 中的嵌套数组更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个集合,其结构是:-

I have collection the structure of which is :-

Subscribed.insert({ "name": "Manager1", "emailId": "arora.priya4172@gmail", "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" } } )

更多推荐

mongodb 中的嵌套数组更新

本文发布于:2023-11-22 15:26:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1617968.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   数组   mongodb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!