MongoDB commands

Connect MongoDB on server
1. Use SSH to connect with port 22
2. Connect to MongoDB using command
# mongo

Show all the databases on the server
# show dbs

Connect to Database
# use <DB-NAME>

Show all collections
# show collections

Export all collections
# mongodump -d <DB-NAME> -o /<directory_to_export>

Restore all collections
# mongorestore -d <DB-NAME> /<directory_from_import>

Export single collection
# mongoexport –db <DB-NAME> –collection <COLLECTION-NAME> –out <COLLECTION-NAME>.json

Import single collection
# mongoimport –db <DB-NAME> –collection <COLLECTION-NAME> –file <COLLECTION-NAME>.json