Copying mongodb - mongodb

I have a web service application built using NodeJS. I am using mongodb as database.
The whole thing is in another system(A) in the network. Now I need to copy all the data to the mongodb database in my system(B).
Can anyone tell me the whole procedure in detail, like even from where I should execute the commands also. I am a beginner and have very little knowledge about mongodb.

You can use the db.cloneDatabase() command for that (docs).
Start the mongo shell from the command line on the destination server by running: mongo
Identify the name of the database to copy: use name
Copy the database from the source server: db.cloneDatabase("1.2.3.4")

Use mongodump and mongorestore utility.

Related

Delete or drop Mongodb database on server ecs2 through another server shell file

I am on Linux Server. My MongoDB Database is stored there. Now if I want to delete the database from another machine lets say my development machine, then for that I created the steps but not working for me.
create a delete.sh file
#!usr/bin/env mongo
#instance Ip assume:
mongo 12.122.12.12:27017/tempDatabase --eval "db.dropDatabase"
But I am unable to delete the Database. Any idea that where I have done mistakes. Any interaction is really appreciated

MongoDB migration

Hello I have an ubuntu 14.04 server that is running mongodb 2.4.14. I need to move the mongo instance to a new server. I have installed mongo 3.4.2 on the new server and need to move the databases over. I am pretty new with mongo. I have 2 databases that are pretty big but when I do a mongo dump the file is nowhere near the site of the databases that mongo is showing.I cannot figure out how to get mongoexport to work. What would be the best way to move those databases? If possible can we just export the data from mongo and then import it?
You'll need to give more information on your issue with mongodump and what mongodump parameters you were using.
Since you are doing a migration, you'll want to use mongodump and not mongoexport. mongoexport only outputs a JSON/CSV format of a collection. Because of this, mongoexport cannot retain certain datatypes that exist in BSON and thus MongoDB does not suggest that anyone uses mongoexport for full backups; this consideration is listed on mongo's site.
mongodump will be able to accurately create a backup of your database/collection that mongorestore will be able to restore that dump to your new server.
If you haven't already, check out Back Up and Restore with MongoDB Tools

How to backup Backup mongo db in meteorjs as mongodump is not working

I am new in Meteorjs and i am using mongo db which comes with the meteor package.
I have made one small meteor application using mongodb and now i want to take backup of the mongo db database. I have seen many web sites and still i am not able to backup my data base. Everyone explained the same thing that in mongo db folder use mongodump and mongostore but when i use mongodump and mongostore on my terminal then it displays something like 'mongodump' is not an internal or external source command. Can u please help me in finding out the solution.
I have found that the easiest way to backup your database (or move it between meteor installations for that matter) is to simple copy the files in .meteor\local\db
Then you don't have to worry about all that mongodb dump stuff. Simple.

How to import data into MongoDB from another MongoDB?

I've installed new MongoDB server and now I want to import data from the old one. My MongoDB stores monitoring data and it's a bit problematic to export the data from old database (it's over 10Gb), so I though it might be possible to import directly from DB, but haven't found how to do that with mongoimport.
The export/import would be the fastest option.
But if you really want to bypass it you can use the new server as a replica of the old one, and wait for full replication.
It takes longer but it's an easy way to set up a full copy without impact on the first one.
Follow this:
http://docs.mongodb.org/manual/tutorial/convert-standalone-to-replica-set/
And then, once it's done, change configuration again.
It's easiest than it seems, but I recommend you to do a dry run with a sample database before doing it...
Note that another benefit is that the new replica will be probably smaller in size than the initial database, because MongoDb is not very good at freeing space of deleted members
mongoimport/mongoexport is per collection operating, so it's not proper for this kind of operation.
Instead to use mongodump/mongorestore.
If the old MongoDB instance can be shutdown to do this task, you can shut down it then copy all data files to the new server as its own data. And run the new instance.
Also db.cloneDatabase() can handle it to copy data directly from old instance to new one. It should be slower against copying data files directly.
You can use mongodump and pipe directly to the new database with mongorestore like:
mongodump --archive --db=test | mongorestore --archive --nsFrom='test.*' --nsTo='examples.*'
add --host --port and --username to mongorestore to connect to the remote db.
db.cloneDatabase() has been deprecated for a while.
You can use the copydb command discribed here.
Copies a database from a remote host to the current host or copies a database to another database within the current host.
copydb runs on the destination mongod instance, i.e. the host receiving the copied data.

Could I use MongoDB to attach DB in this way?

We found a way to attach a db to another mongo instance,
that is, we copy db files like test.* from orgin mongo instance to dest mongo instance.
This way is worked if we restart mongo instance correct,
but once we found that this works even we keep mongo instance running without restart it.
So question: Can I just copy db to dest mongo instance without a restart step?
Just copying the database files might not be a good idea, even though it appears to work.
A much cleaner method is to use the db.copyDatabase() shell method.
Another clean method would be to use mongodump to export the source database to a file and then use mongorestore to import it on the destination database.