mongodb - Updating Mongo documents -


i update collection transforming documents form:

{ "_id" : "somestring made", "value" : {     "a" : 0.42361499999999996,     "b" : 3,     "c" : "foo",     "d" : "bar" } } 

to form (with new id's):

{ "_id" : objectid("77d987f6dsf6f76sa7676df"), "a" : 0.42361499999999996, "b" : 3, "c" : "foo", "d" : "bar"  } 

so take fields out of object "value" , reset id real document id.

first document , convert required format , remove old doc , again insert modified 1 . like

db.collection.find({}).foreach(function(doc){     var obj = { : doc.value.a,                  b : doc.value.b,                 c : doc.value.c,                 d : doc.value.d};      db.collection.remove(doc);      db.collection.insert(obj); }); 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -