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

_id not preserved when saving to different collection

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • 2.4.2
    • None
    • None
    • None
    • 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.

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

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: