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

_id not preserved when saving to different collection

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 2.4.2
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      Ubuntu 12.10
    • Operating System:
      Linux
    • Steps To Reproduce:
      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

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: