Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The nsInclude parameter of mongorestore is having no effect

I've been pouring over the mongorestore documentation trying to figure out why my mongorestore command is restoring everything in my collection, despite including --nsInclude

This is the command I have tried (I have also experimented with parameter order, which seems not to matter, as expected).

mongorestore --nsInclude=myns.mycollection --uri mongodb://user:pass@mongo/myns?authSource=admin --gzip --drop --preserveUUID --archive="/data/backups/myns/myns.bson.gz"

(if it matters) I created the file like this:

mongodump --uri mongodb://user:pass@mongo/myns?authSource=admin --gzip --archive="/data/backups/myns/myns.bson.gz"

Interestingly, my program output includes this statement:

The --db and --collection flags are deprecated for this use-case; please use --nsInclude instead, i.e. with --nsInclude=${DATABASE}.${COLLECTION}

(even though --db and --collection are nowhere in the command)

There are many examples online of mongorestore working well with --nsInclude. This surely isn't a bug, is it?

Full mongorestore output:

mongodump --uri mongodb://user:pass@mongo/myns?authSource=admin --gzip --archive="/data/backups/myns/myns.bson.gz"
The --db and --collection flags are deprecated for this use-case; please use --nsInclude instead, i.e. with --nsInclude=${DATABASE}.${COLLECTION}
preparing collections to restore from
reading metadata for myns.odwhoms from archive '/data/backups/myns/myns.bson.gz'
restoring myns.odwhoms from archive '/data/backups/myns/myns.bson.gz'
no indexes to restore
finished restoring myns.odwhoms (5 documents, 0 failures)
reading metadata for myns.audits from archive '/data/backups/myns/myns.bson.gz'
restoring myns.audits from archive '/data/backups/myns/myns.bson.gz'
no indexes to restore
finished restoring myns.audits (44 documents, 0 failures)
reading metadata for myns.odwhats from archive '/data/backups/myns/myns.bson.gz'
restoring myns.odwhats from archive '/data/backups/myns/myns.bson.gz'
no indexes to restore
finished restoring myns.odwhats (5 documents, 0 failures)
54 document(s) restored successfully. 0 document(s) failed to restore.

like image 751
Jeff R Avatar asked Dec 19 '25 16:12

Jeff R


1 Answers

After some more experimenting, it seems that my connection string having the database name in it is what was implicitly setting the "--db" option internally. By also adding an --nsInclude parameter, I was merely re-specifying a collection that was already in scope to restore.

If I remove the DB name, nsInclude begins to work properly:

mongorestore --uri mongodb://user:pass@mongo/?authSource=admin --gzip --drop --preserveUUID --archive="/data/backups/myns/myns.bson.gz" --nsInclude=myns.mycollection
like image 110
Jeff R Avatar answered Dec 21 '25 07:12

Jeff R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!