0

I have a mongo json object as follows

{
  "_id" : new BinData(3, "RDHABb22XESWvP83FplqJw=="),
  "name" : "NEW NODE",
  "host" : null,
  "aet" : null,
  "studies" : ["1.3.12.2.1107.5.99.3.30000008061114424970500000589"],
  "testcases" : [new BinData(3, "Zhl+zIXomkqAd8NIkRiTjQ==")],
  "sendentries" : [{
     "_id" : "1.3.12.2.1107.5.99.3.30000008061114424970500000589",
     "Index" : 0,
     "Type" : "Study"
     }, {
      "_id" : "cc7e1966-e885-4a9a-8077-c3489118938d",
      "Index" : 1,
      "Type" : "TestCase"
    }]
}

The fields "Studies" and "TestCases" are now obsolete and I am now storing that information in a new field called SendEntries. I would like to get rid of the Studies and TestCases from the old entries and unmap those fields going forward. I want to know how I can update my current collections to get rid of the Studies and TestCases fields.

I'm just few weeks into Mongo.

Goks
  • 9
  • 1
  • 5
  • possible duplicate of [How to remove deprecated fields in Mongo?](http://stackoverflow.com/questions/8641340/how-to-remove-deprecated-fields-in-mongo) – joao Mar 20 '14 at 10:28

2 Answers2

0

Use $unset, there's a manual page e.g.

db.yourCollection.update( { }, { $unset: { Studies: "", testcases: "" } }, { multi: true } )

arober11
  • 1,969
  • 18
  • 31
  • Thank guys. I used $unset. Using MongoVUE is probably a easy way for starters. Just updating the way I solved it in MongoVUE Select the collection you want to change, right click and select update. In the "Enter Find Json" window type the following { "Field You want to delete": { $exists : true } } Click count to find the number of instances. In the 'Enter Update Json' put the following: { $unset : { "Field You want to delete" : "number of instances"} } Hit update. If everything goes well your field should have disappeared. – Goks Mar 20 '14 at 10:43
0

You can use the $unset operator with update.

db.collection.update({},
    { $unset: {
      "studies": "",
      "testcases": ""
    },
    { "upsert": false, "muti": true }
)

And that will remove all of the fields from all of your documents in your collection

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317