MongoDB Export a collection (general)

MongoDB Export a collection (general)

MongoDB is a NoSQL database, that stores information in documents instead of tables, and it can store a lot of information.

It looks like that:

test> db.test.find()
[ { _id: ObjectId(’69edadcfb6b4cff75744ba89′), name: ‚Morgentest‘ } ]

You see MongoDB follows the JSON standard for documents. Ok, MongoDB stores this for human-readable information in special format that is called BSON, but this is not the subject of this blog entry.

If you have a full database (or an important database) for example my Spanish database where I have stored 1 000 entries, it should to have a backup if something goes wrong with the database or with the program for a good sleep in the night.

You can use this kind of command:

mongoexport –db=Espana –collection=ciudad –out=/home/xxx/Documents/espania_ciudad_backup_13072026_1000_Eintraege.json

mongoexport is the name of the program

  • db = the database
  • collection = your collection
  • out = where you want to save the JSON file and the name of your file.

mongoexport comes with a program collection

mongodb-database-tools-100.17.0-1.x86_64

In my case it is a rpm file on Linux.

With this command without root permission you can check your installation, if you have installed, otherwise you can install it.

[xxxx@linux ~]$ rpm -qa | grep mongo
mongodb-database-tools-100.17.0-1.x86_64
mongodb-org-database-tools-extra-8.0.26-1.el9.x86_64
mongodb-org-tools-8.0.26-1.el9.x86_64
mongodb-org-server-8.0.26-1.el9.x86_64
mongodb-org-mongos-8.0.26-1.el9.x86_64
mongodb-org-database-8.0.26-1.el9.x86_64
mongodb-org-8.0.26-1.el9.x86_64
mongodb-compass-1.49.8-1.el8.x86_64
mongodb-mongosh-2.9.2-1.el8.x86_64

By the way mongodb-compass is the graphical tool for the Shell (the command prompt of the Mongosh).

Die Kommentare sind geschlossen.