mongorestore --nsInclude not using namespace...

602 views
Skip to first unread message

Mike5

unread,
Mar 27, 2018, 2:55:44 PM3/27/18
to mongodb-user
Mongodb 3.6.1 on Windows 10

I have taken dumps from multiple databases and placed all in a single folder.  I am trying to run mongorestore so that it restores only those collections in a single database:

mongorestore -v -d TargetDb1 --nsInclude 'TargetDb1.*' --drop  .

The problem is that mongorestore is loading all collections from all databases into TargetDb1.  I was expecting --nsInclude to select only those collections that have TargetDb1 in its namespace.  Otherwise, having a namespace is rather pointless.

Got any suggestions what I'm doing wrong?




This email and any files transmitted with it are considered privileged and confidential unless otherwise explicitly stated otherwise. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. All email data and contents may be monitored to ensure that their use is authorized, for management of the system, to facilitate protection against unauthorized use, and to verify security procedures, survivability and operational security. Under no circumstance should the user of this email have an expectation of privacy for this correspondence.

Wan Bachtiar

unread,
May 2, 2018, 2:33:50 AM5/2/18
to mongodb-user

Got any suggestions what I’m doing wrong?

Hi Mike,

When you created a data export using mongodump the output (default) would be in a directory structure as below :

dump/
    database1/
        collection1.bson
        collection1.metadata.json
        collection2.bson
        collection2.metadata.json
        ...
    database2/
        collection3.bson
        collection3.metadata.json
        collection4.bson
        collection5.metadata.json
        ...
    ...

Then, you can restore using mongorestore‘s option —nsInclude to specify which collections to restore. For example, by executing below:

mongorestore -v --nsInclude "database1.*" --drop dump/

The nsInclude statement specifies to only restore content in the database1 database. For your use case, that would be --nsInclude 'TargetDb1.*'.
See also Restore Collection Using Wild Cards

Regards,
Wan

Reply all
Reply to author
Forward
0 new messages