[SERVER-9385] Shell ignores modified object's "_id" field Created: 18/Apr/13  Updated: 11/Jul/16  Resolved: 18/Apr/13

Status: Closed
Project: Core Server
Component/s: JavaScript, Shell
Affects Version/s: 2.4.2
Fix Version/s: 2.4.3, 2.5.0

Type: Bug Priority: Blocker - P1
Reporter: Ben McCann Assignee: Mathias Stearn
Resolution: Done Votes: 1
Labels: bson, encoding
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File server9385.js    
Issue Links:
Depends
Duplicate
is duplicated by SERVER-9485 Copying documents across collections ... Closed
is duplicated by SERVER-9523 _id not preserved when saving to diff... Closed
Related
Operating System: ALL
Participants:

 Description   

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



 Comments   
Comment by auto [ 18/Apr/13 ]

Author:

{u'date': u'2013-04-18T12:42:40Z', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: SERVER-9385 Make sure _id fields are extracted from modified lazy V8 objects
Branch: v2.4
https://github.com/mongodb/mongo/commit/022affc651140b5ad28ff5a48b5e4564e1d97317

Comment by Daniel Pasette (Inactive) [ 18/Apr/13 ]

Planning on releasing 2.4.3 next week with this fix.

Comment by Ben McCann [ 18/Apr/13 ]

Any idea when there will be a 2.4.3 release with the fix?

Comment by auto [ 18/Apr/13 ]

Author:

{u'date': u'2013-04-18T12:42:40Z', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: SERVER-9385 Make sure _id fields are extracted from modified lazy V8 objects
Branch: master
https://github.com/mongodb/mongo/commit/d10d06711be066d30a8c54bc34f0de712a4bf261

Comment by Eliot Horowitz (Inactive) [ 18/Apr/13 ]

Bad commit is 1a6239025624c7660b65970d3258f1a242ab4512

Generated at Thu Feb 08 03:20:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.