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

renameCollection creates an empty collection when run from a script

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.0.4
    • Component/s: JavaScript, Shell
    • Labels:
      None
    • ALL

      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.

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

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

              Created:
              Updated:
              Resolved: