meteor - How can I update a single child document in a MongoDB document array using something like $set and $elemMatch? -


i have collection structure so:

albums: {     2obkjqyfwf3vrgdj4: {         _id: "2obkjqyfwf3vrgdj4",         titles: [             {                 titletext: "i album"             },             {                 titletext: "this other title"             }         ]     } } 

i want below update titletext equal something, change it:

db.albums.update({"_id": "2obkjqyfwf3vrgdj4", "titles": {$elemmatch: {"titletext": "i album"}}},     {$set: {         "titles.titletext": "i not album"     } ) 

i know foreach, seems lot of wasted resources plan on having index on titles.titletext.

is there i'm missing, or there not simple way this? i'm using meteor, don't think should change of logic if there way in mongodb.

thanks everyone!

turns out question repost of link

this issue can solved in mongodb doing,

db.albums.update({         "_id": "2obkjqyfwf3vrgdj4",         "titles.titletext": "i album"     },     {$set:         {"titles.$.titletext": "i not album"}     } ) 

when previous question posted positional operator wasn't supported minimongo. of mongo selectors can't used client side code , security reasons.

the method above have called meteor.method() on server.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -