I have a collection structure like so:
albums: {
2oBkjqYFwf3vrgDj4: {
_id: "2oBkjqYFwf3vrgDj4",
titles: [
{
titleText: "i am an album"
},
{
titleText: "this is my other title"
}
]
}
}
I want to do something like the below to update where the titleText is equal to something, then change it:
db.albums.update({"_id": "2oBkjqYFwf3vrgDj4", "titles": {$elemMatch: {"titleText": "i am an album"}}},
{$set: {
"titles.titleText": "i am not an album"
}
)
I know I could do a foreach, but this seems like a lot of wasted resources as I plan on having an index on titles.titleText
.
Is there something I'm missing, or is there not a simple way to do this? I'm using Meteor, but I don't think it should change any of the logic if there is a way to do this in MongoDB.
Thanks everyone!