Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-9523

_id not preserved when saving to different collection

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.2
    • Component/s: None
    • None
    • Environment:
      Ubuntu 12.10
    • Linux
    • Hide

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

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

      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);
      });

            Assignee:
            Unassigned Unassigned
            Reporter:
            aaronyo Aaron Boyd
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: