Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-2379

mongodump/mongorestore error if source database has an invalid index option

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical - P2
    • Resolution: Fixed
    • 4.2.0, 3.6.14, 3.4.23
    • 100.0.0
    • mongorestore
    • None
    • Not Needed

    Description

      Older driver versions allowed invalid index fields. When one of these invalid index fields exists, it gets dumped by mongodump and then upon mongorestore, the process encounters a "The field 'XXX' is not valid for an index specification" error.  For example:

      2019-09-27T04:03:10.421-0700	Failed: testdb.food: error creating indexes for testdb.food: createIndex error: (InvalidIndexSpecificationOption) The field 'safe' is not valid for an index specification. Specification: { key: { a: 1.0 }, name: "a_1", ns: "testdb.food", safe: true }
      

      Possible workarounds:

      • Delete and re-create the index. Not a great option since dropping the index to re-create it could significantly affect performance.
      • Perform the mongorestore with the "–noIndexRestore" option

      Reproduction steps:

      1. On a deployment running 3.2 or earlier, create an index with an invalid option using the mongo shell. A common invalid option previously introduced by one of the drivers was "safe".
      2. Upgrade it to 3.4
      3. Take a mongodump (any version, including 4.2.0)
      4. Run mongorestore (any version, including 4.2.0)

      Example of creating an index with an invalid option (on deployment running 3.2.23):

      > db.foo.insert({a:1})
      WriteResult({ "nInserted" : 1 })
      > db.foo.drop()
      true
      > db.foo.insert({"a":1})
      WriteResult({ "nInserted" : 1 })
      > db.food.createIndex({"a":1},{"safe": true})
      {
      	"createdCollectionAutomatically" : true,
      	"numIndexesBefore" : 1,
      	"numIndexesAfter" : 2,
      	"ok" : 1
      }
      

       

       

       

       

       

      Attachments

        Issue Links

          Activity

            People

              tim.fogarty@mongodb.com Tim Fogarty
              angela.shulman@mongodb.com Angela Shulman (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: