> db.clients.update({'_id':ObjectId("4cc45467c55f4d2d2a000002")}, {'$set':{'_id':ObjectId("4c8a331bda76c559ef000004")}});Mod on _id not allowed
更新也没有完成。我怎么才能真正更新它?
小唯快跑啊
浏览 3374回答 3
3回答
弑天下
你不能更新它。您必须使用新的_id,然后删除旧文档。// store the document in a variabledoc = db.clients.findOne({_id: ObjectId("4cc45467c55f4d2d2a000002")})// set a new _id on the documentdoc._id = ObjectId("4c8a331bda76c559ef000004")// insert the document, using the new _iddb.clients.insert(doc)// remove the document with the old _iddb.clients.remove({_id: ObjectId("4cc45467c55f4d2d2a000002")})