Change all document attachments

In the mongos shell, how would I go through and change each document in reviews.categoryto "category 2"

The structure of my documents:

{
   "_id": ObjectId("4fb3f443b1445d24fc000000"),
   "reviews": {
     "0": {
       "category": "category 1"
    },
     "1": {
       "category": "category 1"
    },
     "2": {
       "category": "category 1"
    },
     "3": {
       "category": "category 1"

    } 
  }
}
+3
source share
1 answer

You will need to do this yourself in your application code, requesting a document and flipping all your attached documents; and then save it back to MongoDB.

To prevent race conditions with this, please read the section to compare and exchange for http://www.mongodb.org/display/DOCS/Atomic+Operations

There is currently an open ticket for this to add this feature to MongoDB. You might want to vote for him: https://jira.mongodb.org/browse/SERVER-1243

+5

All Articles