Convert (.net) BsonDocument string to (java) DBObject

In the publish stream, I need to insert DBObject into the db mongo collection using Java.

I get the object as a String, and this was passed to me from a .NET application that used article.ToBsonDocument().ToJson() in POCO.

On my side of the stream, in Java, I tried just using BasicDBObject doc = (BasicDBObject) JSON.parse(content); but I get com.mongo.util.JSONParseException in Date:

 "CreationDate" : ISODate("2013-03-18T08:50:53Z") 

I can change the way I create content in C #, and I can change the way I write to the database in java, the only restriction is that it must be passed as a string between two systems.

Any suggestions?

EDIT Thanks to the hint from @Jim Dagg below, some search queries for ISODate and BsonDocument turned out to be this stone , Changing C # code to use

 article.ToBsonDocument().ToJson(new JsonWriterSettings{OutputMode = JsonOutputMode.Strict}); 

fixed it.

+4
source share
1 answer

Calling the ISODate constructor causes a problem. From the problem with JIRA MongoDB :

The parser accepts these two date formats: seconds → "yyyy-MM-dd'T'HH:mm:ss'Z'" or seconds.milleseconds → "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" Just add seconds to your $date value and the aggregation command should work. Here's the JSON document that I was successful: { "aggregate" : "test", pipeline : [ {$match : { date : { $date : "2012-05-01T12:30:00Z" } } } ] }

If you remove the ISODate constructor and simply visualize your date as (for example) "2013-03-18T08:50:53Z" , you should be in business.

+2
source

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


All Articles