Mongodb how to Import / Export

For Importing a mongodb use the following command

$ mongodump --db database_name

This will dump the json/bson files into dump/db_name folder
Or specify a directory with -o option

$ mongodump --db database_name -o path_to_folder

For Exporting a mongodb use the following command

$  mongorestore --db database_name path_to_the_json_bson_files

path_to_the_json_bson_files => That we already imported and stored before.

Advertisements

How to reinstall mongodb in ubuntu linux

Before reinstalling mongodb, in your linux system check whats installed in the system


$ sudo dpkg -l | grep mongo
ii mongodb-org 2.6.3 amd64 MongoDB open source document-oriented database system (metapackage)
ii mongodb-org-mongos 2.6.3 amd64 MongoDB sharded cluster query router
ii mongodb-org-server 2.6.3 amd64 MongoDB database server
ii mongodb-org-shell 2.6.3 amd64 MongoDB shell client
ii mongodb-org-tools 2.6.3 amd64 MongoDB tools

Remove all

$ sudo apt-get remove mongodb*

Install mongodb again, check mongodb org


$ sudo apt-get install -y mongodb-org

For particular version

$ sudo apt-get install -y mongodb-org=2.6.5 mongodb-org-server=2.6.5 mongodb-org-shell=2.6.5 mongodb-org-mongos=2.6.5 mongodb-org-tools=2.6.5

check whats newly installed

$ sudo dpkg -l | grep mongo
ii mongodb-org 2.6.8 amd64 MongoDB open source document-oriented database system (metapackage)
ii mongodb-org-mongos 2.6.8 amd64 MongoDB sharded cluster query router
ii mongodb-org-server 2.6.8 amd64 MongoDB database server
ii mongodb-org-shell 2.6.8 amd64 MongoDB shell client
ii mongodb-org-tools 2.6.8 amd64 MongoDB tools

check mongodb server status


$ sudo service mongod status

Start mongodb server

$ sudo service mongod start

Start mongo shell

$ mongo

check mongodb log file here

$ tail -n 200 /var/log/mongodb/mongod.log

mongodb connection issue: `connect’: Failed to connect to a master node at localhost:27017 (Mongo::ConnectionFailure)

You just try to start the mongodb by

service mongod start

or

start mongod

And check mongodb process is running by checking

ps aux | grep mongo

You can see the status by

service mongod status

If it is not starting then try to remove the mongod lock file by,

rm /var/lib/mongodb/mongod.lock

Then start the mongodb server again.