changing field in a set object in mongodb -


i have document in mongo:

{     id: objectid,     list: [      {         id: internalobjectid1,         enabled: true     },     {         id: internalobjectid2,         enabled: false     }] } 

i need change enabled field. how can it?

use positional $ operator. suppose have following document in collection list element value array of embedded documents:

{     "_id" : objectid("551be1a04db8a16ac729432e"),     "list" : [          {             "id" : objectid("54f43159c922ac0b4387ef9c"),             "enabled" : true         },          {             "id" : objectid("54f43159c922ac0b4387ef9d"),             "enabled" : false         }     ] } 

the following update value of enabled field in embedded document id of 54f43159c922ac0b4387ef9d true:

db.collection.update(    {          "_id": objectid("551be1a04db8a16ac729432e"),         "list.id": objectid("54f43159c922ac0b4387ef9d")     },    {         "$set": {"list.$.enabled": true}     } ) 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -