关于 mongodb _id key:
对于更新一个document 不会造成_ID被修改的证明:
> db.version(); 3.0.2 > db.dbdao_student.insert({student_name:"maclean",age:20,sex:"male",score:100}); WriteResult({ "nInserted" : 1 }) > db.dbdao_student.update({student_name:"maclean"},{"student_name" : "maclean", "age" : 20, "sex" : "male", "score" : 100}); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > > db.dbdao_student.find(); { "_id" : ObjectId("5545bcff5714fbdfcb483510"), "student_name" : "maclean", "age" : 20, "sex" : "male", "score" : 100 } > > db.dbdao_student.update({student_name:"maclean"},{"student_name" : "maclean", "age" : 21, "sex" : "male", "score" : 100}); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.dbdao_student.find(); { "_id" : ObjectId("5545bcff5714fbdfcb483510"), "student_name" : "maclean", "age" : 21, "sex" : "male", "score" : 100 } > > db.dbdao_student.update({student_name:"maclean"},{"student_name" : "maclean", "age" : 25, "sex" : "male", "score" : 100}); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > > db.dbdao_student.find(); { "_id" : ObjectId("5545bcff5714fbdfcb483510"), "student_name" : "maclean", "age" : 25, "sex" : "male", "score" : 100 } > > db.dbdao_student.update({student_name:"maclean"},{"student_name" : "maclean", "age" : 25}); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.dbdao_student.find(); { "_id" : ObjectId("5545bcff5714fbdfcb483510"), "student_name" : "maclean", "age" : 25 } > db.dbdao_student.find(ObjectId("5545bcff5714fbdfcb483510")); { "_id" : ObjectId("5545bcff5714fbdfcb483510"), "student_name" : "maclean", "age" : 25 }