From Java driver, I want to save a document that looks like below json in MongoDb
{ "ts" : Timestamp(1421006159, 4)}
Run Code Online (Sandbox Code Playgroud)
Options I tried.
Option 1: Map doc= new HashMap(1);
doc.put("ts", new BSONTimeStamp());
Run Code Online (Sandbox Code Playgroud)
It results in the below not required format
{"ts" : {
"_inc" : 0,
"_class" : "org.bson.types.BSONTimestamp"
}}
Run Code Online (Sandbox Code Playgroud)
Option 2:
doc.put("ts",new Timestamp(new Date().getTime()));
Run Code Online (Sandbox Code Playgroud)
it results in :
{"ts" : ISODate("2015-01-12T05:36:43.343Z")}
Run Code Online (Sandbox Code Playgroud)