Thanks to visit codestin.com
Credit goes to github.com

Skip to content

imaksp/mongo-help

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Mongo import/export commands

INSTALLATION

Follow this link for installation steps.

EXPORT COLLECTION (JSON with preserve BSON types)

mongoexport --uri="mongodb://127.0.0.1:27017/dbName" --jsonFormat=canonical  --collection=textcontent  --out=textcontent.json

EXPORT COLLECTION (CSV with specific fields)

mongoexport --uri="mongodb://127.0.0.1:27017/dbName" --collection=textcontent --type=csv --fields=name,address --out=/backups/collection.csv

IMPORT COLLECTION

Here mode can be any one from insert, upsert, merge & delete see this for details

mongoimport --uri="mongodb://127.0.0.1:27017/dbName" --collection=textcontent --type=json --mode=upsert  --file=./textcontent.json

EXPORT ALL (mongodump)

Here remove db name from URI to export all databases.

mongodump --uri="mongodb://127.0.0.1:27017/dbName" --out=./2023-06-09

IMPORT ALL (mongorestore)

Here --dir specifies dump dir location for restore & command will automatically pick database name from dump dir.

mongorestore --uri="mongodb://127.0.0.1:27017" --dir=./2023-06-09

About

Mongo Import/Export Commands

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published