How to convert the MongoDB archive file to JSON format?

If I upload the database as follows:

mongodump --archive=out.mdb

Is there a way to convert out.mdbto a flat JSON file? If so, how? (for example, if I just wanted to restore one document)

+4
source share
2 answers

mongoexport

I believe the only way is from the database using mongoexport:

mongoexport --db yourdb -c yourCollection --out yourCollection.json

warning from mongo

Just pay attention to the following (from the page ):

WARNING

mongoimport mongoexport . BSON, JSON BSON. mongodump mongorestore, Backup MongoDB .

+4
    Command for export :


mongoexport --db <dbname> --collection <collectionname> --out collection.json
    Once exported, if there are BSON data is there, we can follow the below methods

Official MongoDB Java Driver comes with **utility methods for parsing JSON to BSON and serializing BSON to JSON**.
import com.mongodb.DBObject;
import com.mongodb.util.JSON;
DBObject dbObj = ... ;
String json = JSON.serialize( dbObj );
DBObject bson = ( DBObject ) JSON.parse( json );
The driver can be found here: https://mongodb.imtqy.com/mongo-java-driver/
    In this way, if we take, we can convert easily.
+1

Source: https://habr.com/ru/post/1659238/


All Articles