Reassign MongoDB _id in shell -
i'm trying use mongodb reassign ids. however, not setting ids equal value assign, rather creating new objectid. how assign own id?
> db.pgithub.find(); { "_id" : objectid("516f202da1faf201daa15635"), "url" : { "raw" : "https://github.com/quatlus", "domain" : "github.com", "canonical" : "https://github.com/quatlus" } } { "_id" : objectid("516f202da1faf201daa15636"), "url" : { "raw" : "https://github.com/quasii", "domain" : "github.com", "canonical" : "https://github.com/quasii" } } > db.pgithub.find().foreach(function(myprofile) { var oldid = myprofile._id; myprofile._id = 'exampleid'; db.pgithub.save(myprofile); db.pgithub.remove({_id: oldid}); }); > db.pgithub.find(); { "_id" : objectid("516f204da1faf201daa15637"), "url" : { "raw" : "https://github.com/quatlus", "domain" : "github.com", "canonical" : "https://github.com/quatlus" } } { "_id" : objectid("516f204da1faf201daa15638"), "url" : { "raw" : "https://github.com/quasii", "domain" : "github.com", "canonical" : "https://github.com/quasii" } }
i'm using mongo 2.4.2
ben, statements correct. it's mongo shell 2.4.2 behaves somehow different others (server not affected). can use mongo shell binary 2.4.1 purpose.
Comments
Post a Comment