Hello, I need some help updating the subdocument of a subdocument. I
want to change the active value of one of the images which is embedded
within the case document to false. Any help is appreciated. Thank You.
Marc
unread,
Oct 26, 2011, 3:55:04 PM10/26/11
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongodb-user
You can do this one of three ways using the $set command.
Unfortunately, you will have to know the position of the sub-document
in at least one of the arrays. Mongo does not support multiple
positional operators. The following will not work:
> db.foo.update({"cases.id":"4ea82f1786097", "cases.images.caseid":"4ea82f1786097"}, {$set:{"cases.$.images.$.active" : false}})
can't append to array using string field name [$]
>
Hopefully the above examples and documents will help you accomplish
what you need to do. Good Luck! If you have any additional
questions, the MongoDB community is here to help!
Faizan Sattar
unread,
Oct 26, 2011, 6:48:57 PM10/26/11
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
On Oct 26, 3:55 pm, Marc <m...@10gen.com> wrote:
> You can do this one of three ways using the $set command.
>
> > db.foo.update({"_id" : ObjectId("4ea82f17f53c46c29230a887")}, {$set:{"cases.0.images.0.active" : false}})
>
> -- or --
>
> > db.foo.update({"cases.id":"4ea82f1786097"}, {$set:{"cases.$.images.0.active" : false}})
>
> -- or --
>
> > db.foo.update({"cases.images.caseid":"4ea82f1786097"}, {$set:{"cases.0.images.$.active" : false}})
>
> The "$" character acts as a pointer to the location in the array where
> the document matching the query was found. Here is a link to the "The
> $ positional operator" section of the update() section of the MongoDB
>
> Unfortunately, you will have to know the position of the sub-document
> in at least one of the arrays. Mongo does not support multiple
> positional operators. The following will not work:
>
> > db.foo.update({"cases.id":"4ea82f1786097", "cases.images.caseid":"4ea82f1786097"}, {$set:{"cases.$.images.$.active" : false}})
>
> can't append to array using string field name [$]
>
>
>
> You may also find the Mongo Document on Dot Notation to be useful:http://www.mongodb.org/display/DOCS/Dot+Notation+(Reaching+into+Objects) >