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

mongorestore --noIndexRestore inhibits empty collection creation

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 3.2.0
    • Fix Version/s: 3.2.4, 3.3.3
    • Component/s: mongorestore
    • Labels:
      None

      Description

      An empty collection will be dumped as a 0 byte .bson file. When running mongorestore normally, the empty collection will be correctly created. However, if --noIndexRestore is specified then the empty collection will not be created. If the server is running 3.2, then this prevents subsequent oplog replay from working (SERVER-17634), which impedes the workaround for TOOLS-176.

      Reproducer:

      > use test
      > db.dropDatabase()
      > db.createCollection("test")
      $ mongodump
      > db.dropDatabase()
      > show collections   // returns nothing
      $ mongorestore
      > show collections   // shows "test"
      > db.adminCommand({applyOps: [ { ts: Timestamp(1452934862,5), h: NumberLong("6736086318751491068"), v: 2, op: "i", ns: "test.test", o: { _id: 1 }, o2: {} } ] })       // succeeds
      { "applied" : 1, "results" : [ true ], "ok" : 1 }
      > db.dropDatabase()
      $ mongorestore --noIndexRestore
      > show collections   // returns nothing, but should show "test"
      > db.adminCommand({applyOps: [ { ts: Timestamp(1452934862,5), h: NumberLong("6736086318751491068"), v: 2, op: "i", ns: "test.test", o: { _id: 1 }, o2: {} } ] })       // fails with:
      {
              "applied" : 1,
              "code" : 26,
              "errmsg" : "Failed to apply insert due to missing collection: { ts: Timestamp 1452934862000|5, h: 6736086318751491068, v: 2.0, op: \"i\", ns: \"test.test\", o: { _id: 1.0 }, o2: {} }",
              "results" : [
                      false
              ],
              "ok" : 0
      }
      

      Workaround:

      Instead of doing:

      mongorestore --noIndexRestore --oplogReplay dump
      

      it is possible to do:

      mongo --eval 'db.getSiblingDB("db").createCollection("collection")'
      # repeat for each empty collection, ie. each 0 byte .bson file under `dump`
      mongorestore --noIndexRestore --oplogReplay dump
      

      However, if --drop is used then the workaround is more complicated. Instead of doing:

      mongorestore --drop --noIndexRestore --oplogReplay dump
      

      it should be possible to do:

      mongorestore --drop --noIndexRestore dump
      mongo --eval 'db.getSiblingDB("db").createCollection("collection")'
      # repeat for each empty collection, ie. each 0 byte .bson file under `dump`
      mkdir justoplog ; mv data/oplog.bson justoplog
      mongorestore --oplogReplay --noIndexRestore justoplog
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mpobrien Michael O'Brien
              Reporter:
              kevin.pulo Kevin Pulo
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: