-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 3.2.0
-
Component/s: mongorestore
-
None
-
Server Tools 10 (02/19/16)
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
- related to
-
TOOLS-176 Dump/Restore with --oplog not point-in-time
- Closed
-
TOOLS-852 mongorestore --noDataRestore
- Accepted
-
SERVER-17634 do not apply replicated insert operations on missing collections
- Closed