-1

I have 4 local dbs in my /data/db directory

$ mongo
MongoDB shell version: 3.2.9
connecting to: db-A

$ show dbs
db-A  0.00gb
db-B  0.02gb
db-C  0.08gb
db-D  0.00gb

When I try to run:

$ mongorestore -h dsxxxxx.mlab.com:xxxxx -d <dbname> -u <user> -p <password> /data/db`

It imports the db-A database to my mlab db, how do I specify that I want to import the db-C databse?

Community
  • 1
  • 1
  • By specifying `-d db-C` just as the usage prompts you to at ``. Unless of course your "backup" does not actually contain a backup of that database. It looks like you in fact have "no backup at all" though and are trying to run directly off the database files. You cannot do that. Instead create a backup via `mongodump` and then use `mongorestore` to populate the target. – Neil Lunn Jul 20 '17 at 03:39
  • Of note. Prior to MongoDB 3.x it was possible that `mongorestore` and `mongodump` could access the database files directly ( though you should not be running `mongod` whilst doing it ). This was removed as of this release since the mechanism used "presumed" the data format to be the MMAPv1 form. With the addition of new database engines, this is no longer possible for the tools, and both work by communicating with a running instance instead. – Neil Lunn Jul 20 '17 at 03:57
  • The thing is I grabbed that line straight from mlabs docs and they had actually filled in `` with the name of my db on mlabs so I assumed that's correct? For context, what I'm trying to accomplish is transferring the data in my local `db-C` to the brand new db I made on mlabs, if that helps... – Amir Ghafouri Jul 20 '17 at 04:11
  • For context `/data/db` is clearly where the "database files are" and not where your "backup" resides. Perhaps you should read the actual MongoDB documentation for [`mongorestore`](https://docs.mongodb.com/manual/reference/program/mongorestore/) and [`mongodump`](https://docs.mongodb.com/manual/reference/program/mongodump/) instead of "external" documentation sources. – Neil Lunn Jul 20 '17 at 04:27
  • Thanks. I didn't understand that there was a difference between the types of files. Got what I wanted done by running `mongodump` in `/data` which created a `data/dump` folder next to the existing `/data/db` folder, and then I could run `$ mongorestore -h dsxxxxx.mlab.com:xxxxx -d -u -p /data/dump/db-C` – Amir Ghafouri Jul 20 '17 at 04:52

2 Answers2

1

This is an old post, but I figured i would post my findings.

If you use mongodump -d dbname -o /path/to/folder for all your data bases, you can then use mongorestore /path/to/folder and it will read all of the databases inside the folder.

0

If you are moving data from one mongodb instance to other, you need first dump data out from first database and then you can import it to other. You cannot use mongorestore to read directly source database and "restore" it to new one.

You can use copyDatabase() command at destination mongo to copy whole database from other machine.

There is mongodb-connector what you can use too. Actually it's very handy tool to "replicate" one way between two instances.

JJussi
  • 1,540
  • 12
  • 12