Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- > db.clients.update({ _id: ObjectId("123")}, { $set: { _id: ObjectId("456")}})
- Performing an update on the path '_id' would modify the immutable field '_id'
- // 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")})
- db.status.find().forEach(function(doc){
- doc._id=doc.UserId; db.status_new.insert(doc);
- });
- db.status_new.renameCollection("status", true);
- db.someCollection.find().snapshot().forEach(function(doc) {
- if (doc._id.indexOf("2019:") != 0) {
- print("Processing: " + doc._id);
- var oldDocId = doc._id;
- doc._id = "2019:" + doc._id;
- db.someCollection.insert(doc);
- db.someCollection.remove({_id: oldDocId});
- }
- });
- {
- "_id":ObjectId("5b5ed345cfbce6787588e480"),
- "title": "foo",
- "description": "bar"
- }
- db.getCollection('myCollection').aggregate([
- {$match:
- {_id: ObjectId("5b5ed345cfbce6787588e480")}
- }
- {$project:
- {
- title: '$title',
- description: '$description'
- }
- },
- {$out: 'myCollection'}
- ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement