New in mongodb, my requirement is to update the _id field for entire collection as follows:
orignal : _id: ObjectId("4cc45467c55f4d2d2a000002")
required: _id: 4cc45467c55f4d2d2a000002
I want to truncate 'ObjectId("' from beginning and '")' from end of all documents from whole collection.
Moreover I have seen following on a similar post but its all manual I have millions of rows/document wish to have a function or some thing to do it of all document.
// store the document in a variable
doc = db.clients.findOne({_id: ObjectId("4cc45467c55f4d2d2a000002")})
// set a new _id on the document
doc._id = ObjectId("4c8a331bda76c559ef000004")
// insert the document, using the new _id
db.clients.insert(doc)
// remove the document with the old _id
db.clients.remove({_id: ObjectId("4cc45467c55f4d2d2a000002")})
Thanks