mongodb-restore icon indicating copy to clipboard operation
mongodb-restore copied to clipboard

Restoring from BSON dump breaks when directory contains metadata files created by mongodump

Open cdxOo opened this issue 8 years ago • 1 comments

By default recent versions of mongodump create metadata files in the form of .metadata.json within the dump diretory. Theese files are not filtered and therefor restore breaks when tying to deserialize them as bson.

I suggest checking for !(/\.metadata\.json$/).test(docName) in fromJSON() before processing them further.

cdxOo avatar Jul 13 '17 02:07 cdxOo

I'm not sure if this is related but I get the following stacktrace from a fresh dump using mongodump:

❯ node seed.js
Error: corrupt bson message
    at deserialize (/path-to-project/node_modules/mongodb-restore/node_modules/bson/lib/bson/parser/deserializer.js:27:9)
    at BSON.deserialize (/path-to-project/node_modules/mongodb-restore/node_modules/bson/lib/bson/bson.js:115:10)
    at /path-to-project/node_modules/mongodb-restore/index.min.js:89:24
    at Array.forEach (<anonymous>)
    at fromBson (/path-to-project/node_modules/mongodb-restore/index.min.js:81:48)
    at /path-to-project/node_modules/mongodb-restore/index.min.js:113:36
    at meta (/path-to-project/node_modules/mongodb-restore/index.min.js:187:16)
    at /path-to-project/node_modules/mongodb-restore/index.min.js:112:18
    at handleCallback (/path-to-project/node_modules/mongodb-restore/node_modules/mongodb/lib/utils.js:95:56)
    at /path-to-project/node_modules/mongodb-restore/node_modules/mongodb/lib/db.js:512:22
❯ tree mongo-seed/dump
mongo-seed/dump
└── reach-engine
    ├── MyDummyCollection.bson
    └── MyDummyCollection.metadata.json

1 directory, 2 files

I'm using mongo:3.4-jessie docker image.

Edit: I deleted MyDummyCollection.metadata.json but it's still failing with the same error.

GabLeRoux avatar Mar 21 '18 14:03 GabLeRoux