'Document (MongoDB) to JSON and vice versa

I am working with Documents of MongoDB in Java .

I want to save the document I got here:

docsInstance = db.getCollection("instance").find().into(new ArrayList<>());

into a JSON file.

And then convert that JSON file back into a Document.

How can I do this in Java?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source