Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Update of Embedded Array Object
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
copypastecoder  
View profile  
 More options Apr 25 2012, 7:42 pm
From: copypastecoder <sur...@gmail.com>
Date: Wed, 25 Apr 2012 16:42:36 -0700 (PDT)
Local: Wed, Apr 25 2012 7:42 pm
Subject: Re: Update of Embedded Array Object

Thanks for your post, i kept trying to update in so many different ways,
and not understanding why somethings like {comments.votes...} wasn't
recognized in an update. For some reason i glossed over the positional
operator, and it's exactly what I needed.

On Wednesday, April 25, 2012 10:53:38 AM UTC-5, Marc wrote:

> The update statement that you provided should work:

> db.pets.save({name:'Mark',pets:[{type:'dog',name:'fido'},{type:'cat',name:' puss'}]})

> > db.pets.save({name:'John',pets:[{type:'dog',name:'rex'}]})
> > db.pets.find().pretty()
> {
>         "_id" : ObjectId("4f981b7231eb8983025f1579"),
>         "name" : "Mark",
>         "pets" : [
>                 {
>                         "type" : "dog",
>                         "name" : "fido"
>                 },
>                 {
>                         "type" : "cat",
>                         "name" : "puss"
>                 }
>         ]
> }
> {
>         "_id" : ObjectId("4f981b9131eb8983025f157a"),
>         "name" : "John",
>         "pets" : [
>                 {
>                         "type" : "dog",
>                         "name" : "rex"
>                 }
>         ]
> }
> > db.pets.update({'name':'Mark',"pets.type":'dog'},
> {$set:{'pets.$.name':'rover'}})
> > db.pets.find().pretty()
> {
>         "_id" : ObjectId("4f981b7231eb8983025f1579"),
>         "name" : "Mark",
>         "pets" : [
>                 {
>                         "name" : "rover",
>                         "type" : "dog"
>                 },
>                 {
>                         "type" : "cat",
>                         "name" : "puss"
>                 }
>         ]
> }
> {
>         "_id" : ObjectId("4f981b9131eb8983025f157a"),
>         "name" : "John",
>         "pets" : [
>                 {
>                         "type" : "dog",
>                         "name" : "rex"
>                 }
>         ]
> }

> The positional operator was introduced in version 1.4.  Are you using
> a really old version of Mongo?  Have you checked for obvious things,
> like typeos and capitalization?

> If your update still does not work, please give the version of Mongo
> that you are using and the exact steps that you take that fail to make
> the update, and we will attempt to reproduce.  Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.