I seem to be having a problem updating an array inside of a mongo collection. Here is an example of what an entry in the collection “orgs” looks like.
{
"_id" : "v5y8nggzpja5Pa7YS",
"name" : "Full name of the organization",
"display_name" : "DISPLAY NAME",
"groups" : [
{
"_id" : "s86CbNBdqJnQ5NWaB",
"name" : "FULL NAME OF THE GROUP",
"display_name" : "DISPLAY NAME",
"description" : "Description",
}
}
If I perform a find with the organizations ID and the group ID I can easily find what I am looking for.
db.orgs.find({_id: org_id, "groups._id": group_id}).fetch()
The problem comes in when I want to update the information stored in the array “groups”. Doing the following will not update the group. (Callback returns with no error, and 0 )
db.orgs.update({ id: org_id, "groups._id": group_id} ,
{$set: { 'groups.$.name': 'Test'}, {} ,my_callback);
It’s probably a misunderstanding of the query. Any help would be greatly appreciated
EDIT: Well this is embarrassing. I wasted 2 hours trying to figure out why my query didn’t work. I forgot the underscore before “id” in the update query… face palm