Farbod Aprin
Farbod Aprin

Reputation: 1176

Export database from MongoDb atlas to the local machine Monogo compass

I have remote database in Atlas with name of "test" and I want to download collection name image_table as a JSON file.

In mac terminal:

$ mongoexport –db test –collection image_table image.json I got the error>

020-01-16T13:49:12.822+0100 error parsing command line options: too many positional arguments: [–db test –collection image_table image.json] 2020-01-16T13:49:12.822+0100 try 'mongoexport --help' for more information

Upvotes: 32

Views: 64879

Answers (5)

Tanmai Kiran Kamat
Tanmai Kiran Kamat

Reputation: 41

This might be the Required Solution:

mongodump --uri="mongodb://username:password@host:port/dbname" --out=/path/to/backup/directory

This will dump all of your collections to /directory

Upvotes: 4

Sanan Ali
Sanan Ali

Reputation: 3427

I wanted to export all the collections from my atlas to local database. After facing a lot of issues with mongodb compass and mongoshell I ended up using NOSQL booster for mongodb. Downloading Link

It exported all the collections at once with ease and then I was able to import them into my local mongodb database using the same tool.

Upvotes: 2

MongoDB Compass has many flaws and may fail you even with such a trivial task as exporting a collection. E.g. it will skip some fields in the export. The app itself says: "The fields displayed are from a sample of documents in the collection...". From my experience, a sample Compass uses is very small. I lost data even when exporting 100 documents or so.

Using mongoexport is easy. If you use mongo 3.6+, this will work:

mongoexport --uri mongodb+srv://<username>@atlas-cluster-url.mongodb.net/<db-name> --collection <collection-name> --out <path-to-export>

Upvotes: 21

Farbod Aprin
Farbod Aprin

Reputation: 1176

I could find a bit more straightforward answer in Mongo Compass :

enter image description here

Just install mongo compass connect to your atlas remote DB: get the hostname like "cluster0-shard-00-00-rcapo.mongodb.net XXXXX" from your remote altas cluster then connect to the database.

then you can download each document as JSON or CSV format. thanks, mongo DB compass developers team.

Upvotes: 18

Arpit Jain
Arpit Jain

Reputation: 1315

I had this same problem. In my case, I was using mongoexport with the --query option, which expects a JSON document, such as:

mongoexport ... --query {field: 'value'} ...

I needed to surround the document with quotes:

mongoexport ... --query "{field: 'value'}" ...

Upvotes: 3

Related Questions