Mongodb java driver 3.0: how to store a JSON document

It looks simple and simple: there is a JSON string, and I want to save it in MongoDB as a JSON document.

In java driver 2.xx, I could use com.mongodb.util.JSON.parse(String jsonString) to get a DBObject and then save it to the collection.

In driver 3.0, JSON.parse still provides DBObject, but the rest of the API uses the org.bson.Document class, which looks incompatible with DBObject.

How to do this in version 3.0 for drivers?

+6
source share
1 answer

For Document use the parse() static helper:

 Document myDoc = Document.parse(jsonString) 
+21
source

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


All Articles