user11327631
user11327631

Reputation:

How to import my mongo db from my local to a remote linux server

I have already export my mongo databse using mongodump and i already have a copy of the folder. Now I want import and use that database to my server which is a linux server , Dont worry I am already connected to the server , I wanted to know how to import mongo db to the server. Import whole collections into a single databsae,

Upvotes: 0

Views: 2153

Answers (1)

Ra Ka
Ra Ka

Reputation: 3055

You can restore backup using MongoRestore. Please follow the official documentation there.

If your backup is simply in BSON files:

mongorestore --host <host-name> --db <db-name> <directory-to-bsonfiles>
//e.g. in case your backup files are in director /home/mongo/backup/<bson files>
mongorestore --db test_db /home/mongo/backup/
//In case mongo server running on particular replicaset, host and port;
mongorestore --host "rs0/11.22.33.44:37568" --db test_db /home/mongo/backup/
//In case you want to restore particular collection only;
mongorestore --db test_db --collection test_collection /home/mongo/backup/test_collection.bson

In case your backup is saved as archived (e.g. gzip, tar etc.)

mongorestore --db test_db --gzip --archive=/home/mongo/backup/test_db-dump-2019-08-08.gzip

Upvotes: 2

Related Questions