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

renameCollection creates an empty collection when run from a script

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Cannot Reproduce
    • 2.0.4
    • None
    • JavaScript, Shell
    • None
    • ALL

    Description

      renameCollection works from the shell:

      > db.oldName.find();
      { "_id" : ObjectId("4df78a754a235ac761000000"), "name" : "user1" }
      > db.oldName.renameCollection("newName");
      { "ok" : 1 }
      > db.newName.find();
      { "_id" : ObjectId("4df78a754a235ac761000000"), "name" : "user1" }

      I created a script "upgrade.js":

      if(db["oldName"].findOne())
      {
          db["oldName"].renameCollection("newName");
      }

      and running it creates an empty "newName" collection:

      > db.oldName.findOne();
      { "_id" : ObjectId("4df78a754a235ac761000000"), "name" : "user1" }
      > db.newName.findOne();
      null

      I can workaround this issue by inserting all the records from the old to the new collection and then dropping the old collection, but its not very clean.

      Attachments

        1. server5997.js
          0.2 kB
        2. test.js
          0.2 kB

        Activity

          People

            Unassigned Unassigned
            awsiv bishwa shrestha
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: