From the Java driver, I want to save a document that looks like json in MongoDb
{ "ts" : Timestamp(1421006159, 4)}
Parameters I tried.
Option 1: Map doc = new HashMap (1);
doc.put("ts", new BSONTimeStamp());
The result is the required format below.
{"ts" : { "_inc" : 0, "_class" : "org.bson.types.BSONTimestamp" }}
Option 2:
doc.put("ts",new Timestamp(new Date().getTime()));
This leads to:
{"ts" : ISODate("2015-01-12T05:36:43.343Z")}
java spring-data-mongodb mongodb bson
hellojava
source share