renameCollection creates an empty collection when run from a script

XMLWordPrintableJSON

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

      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
            Reporter:
            bishwa shrestha
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: