If an object is returned in the shell from a query (or any other way from the server) which is then modified the result will be that the "_id" field will be ignored when being sent to a mongodb server (in the bson encoding process).
This is a bug in javascript (shell/client) but does not effect the server, other than the client not sending the _id field. It is possible to cause this behavior with javascript on the server using $eval (db.eval) or mapReduce, in the reduce phase if the first document in the array is modified (which is not a normal usage pattern).
Orig Description
There's a regression in the 2.4.2 shell, where if I write an object with my own _id, the shell ignores it and creates its own ObjectId. I found this out during a data migration today when my previously working JS function destroyed an entire table's worth of data
http://stackoverflow.com/questions/16071342/reassign-mongodb-id-in-shell
https://groups.google.com/forum/?fromgroups=#!topic/mongodb-user/MzdEDgyl0rU
- is duplicated by
-
SERVER-9485 Copying documents across collections with modification to _id doesn't work
- Closed
-
SERVER-9523 _id not preserved when saving to different collection
- Closed