If I have several documents that use the following structure:
{
"_id" : ObjectId("4f9c6fe033cddec1bea430f2"),
"title" : "Product #1",
"comments" :
[
{
"comment" : "My comment",
"date" : "2012-03-01 00: 00: 00",
"name" : "Test Name",
"username" : "Test Username"
},
{
"comment" : "My comment",
"date" : "2012-03-01 00: 00: 00",
"name" : "Test Name 2",
"username" : "Test Username 2"
}
]
}
Is it possible for me to find all documents that have reviews.name and update it? For example say I want to find all documents with user.name : test name 2 and change it to Cassie. Is that possible? If not would it be better to put the comments in a different collection?
Yes it is possible. You would have to use
comments.usernameto find it and thencomments.$.usernamenote that since you are posting to an array you have to tell mongo to go in there using the $ positional operator