Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 346
Farbod Aprin Avatar asked Jan 16 '20 13:01

Farbod Aprin


People also ask

Can I export database from MongoDB compass?

You can use MongoDB Compass to import and export data to and from collections. Compass supports import and export for both JSON and CSV files.

How do I export a MongoDB database from Atlas?

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.

Can you use MongoDB compass locally?

To use MongoDB Compass, you have to install it first. You can download and install MongoDB Compass from the this page. To connect to your local MongoDB, you set Hostname to localhost and Port to 27017 . These values are the default for all local MongoDB connections (unless you changed them).

Is MongoDB Atlas and Compass same?

MongoDB Atlas belongs to "MongoDB Hosting" category of the tech stack, while MongoDB Compass can be primarily classified under "Database Tools". Some of the features offered by MongoDB Atlas are: Global clusters for world-class applications. Support for 60+ cloud regions across AWS, Azure, & GCP.


2 Answers

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.

like image 71
Farbod Aprin Avatar answered Oct 21 '22 01:10

Farbod Aprin


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>

like image 27
Lukáš Hošták Avatar answered Oct 21 '22 02:10

Lukáš Hošták