Reputation: 23
I created a database using MongoDB on Computer 1. I am trying to load this DB from Computer 2. Could you please help me to do that ?
I tried to set the --dbpath (data\db) in a shared disk F:\ but Computer 2 is not able to recognize the data.
Upvotes: 0
Views: 4828
Reputation: 4609
I found this link more helpful [https://severalnines.com/blog/developer-s-guide-mongodb-replica-sets][1]
Summarising the steps given in above link:
mongod --replSet replicaSetName --dbpath /usr/local/var/mongo/mongod --port 27017
//you can provide any name in place of replicaSetName
2. Enable replSet mode for this instance
rs.initiate()
mongod --config /etc/mongod-secondary.cfg
Sample mongod-secondary.cfg:
systemLog: destination: file path: /Users/log2/mongod.log storage: dbPath: /Users/MongoSample/data net: port: 27019 bindIp: 127.0.0.1 replication: replSetName: replicaSetName
replicaSetName should be the same as given in instance one, db path and log path should be different then the instance 1
rs.add("127.0.0.1:27019");
Thats it!! Please check the link for detailed answer. It has given easier way to create replica's of mongo db instance, the selected answer is correct but somehow difficult to understand thats why posting it here.
Upvotes: 0
Reputation: 346
You can access the mongo cluster from any other node, for that you need to know the port on which the config-server is running on node (Computer) 1. The config-server can be started using the following command. Ideally there should be 3 config servers running on a system so, I am updating the steps to take that into account.
<path-to-mongo>/bin/mongod --configsvr --port <port-1> --dbpath ./shardedcluster/cfg0 --fork
<path-to-mongo>/bin/mongod --configsvr --port <port-2> --dbpath ./shardedcluster/cfg1 --fork
<path-to-mongo>/bin/mongod --configsvr --port <port-3> --dbpath ./shardedcluster/cfg2 --fork
Issue: No shards found. Earlier, I assumed that no shards were necessary to setup this kind of system. However, to overcome this issue you can create a shard server, and initialize it as follows.
<path-to-mongo>/bin/mongod --shardsvr --replSet a --dbpath ./shardedcluster/a0 --port <shard-port> --fork --smallfiles --oplogSize 50
To initialize the Shard, follow the steps below.
<path-to-mongo>/bin/mongo --port <shard-port>
Then, run the command
rs.initiate()
Assuming on Computer 2 you have copied the MongoDB executable. Run the Following command on Computer 2
<path-to-mongodb>/bin/mongos --configdb <C1-IP>:<port-1>,<C1-IP>:<port-2>,<C1-IP>:<port-3> --port 27017
Then run (on Computer-2),
<path-to-mongodb>/bin/mongo --port 27017
27017 is default port, I am using that option just for verbosity.
Note 1 If the shard initialization error persists Run the following command in mongos shell,
sh.addShard("a/<C1-IP>:<Shard-port>")
Note 2 Please, ensure that directory shardedcluster/cfg0, shardedcluster/cfg1, shardedcluster/cfg2, shardedcluster/a exists and have proper write permissions.
To get more details, follow the below link. http://www.mongodbspain.com/en/2015/01/26/how-to-set-up-a-mongodb-sharded-cluster/
I have given you only the required commands out of it.
Upvotes: 1
Reputation: 442
Easiest way, when you need only to copy data but not any configuration of specific DB/collections is mongodump
and mongoimport
. Feel free to take a look at them in mongodb doc.
Upvotes: 0