24

I'm following this tutorial to backup and restore a single MongoDB database.

The backup command -

sudo mongodump --db newdb --out /var/backups/mongobackups/`date +"%m-%d-%y"`

The restore command -

sudo mongorestore --db newdb --drop /var/backups/mongobackups/01-20-16/newdb/

Although it works perfectly, MongoDB gives me this warning while restoring the data -

the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead

Can someone explain how to remove this warning?

I'm using MongoDB 3.4.1 version.

Jyotman Singh
  • 10,792
  • 8
  • 39
  • 55

4 Answers4

33

--nsInclude is new in mongo 3.4.

Instead of older options where db_name and collection_name are given in command line as

mongorestore --db db_name --collection collection_name

namespaces are to be used

mongorestore --nsInclude db_name.collection_name

Similarly

mongorestore --db newdb --drop /var/backups/mongobackups/01-20-16/newdb/

becomes

mongorestore --nsInclude 'newdb.*' --drop /var/backups/mongobackups/01-20-16/
Trein
  • 3,658
  • 27
  • 36
acsrujan
  • 1,011
  • 11
  • 18
1

I was having the same problem, and finally I noticed that I had missed the actual backup folder URL. My backup database folder is in a subfolder.

I was trying for

sudo mongorestore -d database 'Database-13-03-23'

But it should be

sudo mongorestore -d database 'Database-13-03-23/13-03-23/database'
  • Thank you so much! I also had a typo in my restore folder name. The inaccurate error you get when you do this is frustratingly poor. – moodboom Mar 29 '23 at 18:16
0

You could remove --db and the error will goes away:

mongorestore  newdb  --drop /var/backups/mongobackups/01-20-16/

In my case, I didn't need any flag to set the db name.

Reyhaneh Torab
  • 360
  • 5
  • 9
  • Then how does mongorestore know the name of the DB to restore into? Why does the command contradict its own self? When I run it with "--help", it prints ```Usage: mongorestore ... ``` Furthermore, that same help command lists 2 separate "namespace options" sections; the first one shows the "-d" and "-c" options; the second one shows all the switches starting with "ns*". The whole thing is messed up. Whoever created these command-line tools needs to be tarred, feathered, and summarily executed. – Aquarelle Feb 20 '23 at 01:17
-12

just execute command like this:

sudo mongorestore /var/backups/mongobackups/01-20-16
jiucai
  • 21
  • 1
  • 5