[SERVER-9523] _id not preserved when saving to different collection Created: 01/May/13  Updated: 10/Dec/14  Resolved: 01/May/13

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 2.4.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Aaron Boyd Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 12.10


Issue Links:
Duplicate
duplicates SERVER-9385 Shell ignores modified object's "_id"... Closed
Operating System: Linux
Steps To Reproduce:

See description. I'm not sure if moving between db's (rather than within the same db) has anything to do with it.

Participants:

 Description   

This statement did not preserve the _id's of the original (new ones were created):

// move posts to the attic
var attic = connect("localhost:27017/nomic_attic");
db.Post.find(

{type: "VOUCH"}

).sort({_id:-1}).forEach( function(vouchPost) {
attic.VouchPost.save(vouchPost);
});

I had to do this workaround to get the _id to remain unchanged in the new collection:

// move posts to the attic
var attic = connect("localhost:27017/nomic_attic");
db.Post.find(

{type: "VOUCH"}

).sort({_id:-1}).forEach( function(vouchPost) {
var copy = {};
for (var key in vouchPost) {
if (vouchPost.hasOwnProperty(key))

{ copy[key] = vouchPost[key]; }

}
attic.VouchPost.save(copy);
});



 Comments   
Comment by Aaron Boyd [ 01/May/13 ]

Thank you.

Comment by J Rassi [ 01/May/13 ]

This has already been reported, at SERVER-9385. Please upgrade your shell to version 2.4.3, which should fix the issue.

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