Skip to content
SolutionsBased Local
Consult Now
MEAN Stack

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

Ready to Solve Your Most Complex Technical Challenges?

Our senior advisors are ready to help you navigate the ever-evolving technology landscape with precision and expertise.

Schedule a Consultation

Related Articles