I want to output a BsonDocument to a file system, not to mongodb, and read it again using java. But current BasicBSONEncoder only support BSONObject which is the old version.How can I encode BsonDocument into binary? Or is there any way I can convert BsonDocument into BSONObject?
Asked
Active
Viewed 1,893 times
1 Answers
0
The eaziest is to convert the BSON to JSON and use java.io API's to write these data to files. The reverse would be to use Reader API's (BufferedReader or FileReader) to read these back and convert to BSON.
Now to convert BSON to JSON there are multiple ways , depends on utilities used as well as API's on the official Mongo Driver you could choose one of your liking. The reverse is also true , a lot of options are on this thread.
(Creating BSON object from JSON string)
You can also reference https://api.mongodb.com/java/3.0/org/bson/BsonDocument.html#toJson-org.bson.json.JsonWriterSettings-
Hope this helps you :)

Ramachandran.A.G
- 4,788
- 1
- 12
- 24