MongoDB restore warning
Asked Answered
R

4

25

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.

Rutharuthann answered 17/1, 2017 at 18:12 Comment(0)
I
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/
Incogitable answered 18/1, 2017 at 6:37 Comment(1)
I wan't to know why its giving me an error even though I'm restoring from a BSON file.Rutharuthann
B
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'
Benzophenone answered 14/3, 2023 at 4:40 Comment(1)
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.Joly
S
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.

Subzero answered 8/2, 2023 at 8:44 Comment(1)
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 <options> <connection-string> <directory or file to restore> ... 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.Partan
O
-12

just execute command like this:

sudo mongorestore /var/backups/mongobackups/01-20-16
Osmo answered 19/5, 2017 at 7:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.