Wie Sie sparen Typ Timestamp Wert in MongoDb | Java

Vom Java-Treiber, ich möchte ein Dokument speichern, das sieht wie folgt aus json in MongoDb

{ "ts" : Timestamp(1421006159, 4)}

Optionen, die ich ausprobiert habe.

Option 1:
Anzeigen doc= new HashMap(1);

doc.put("ts", new BSONTimeStamp());

Es Ergebnisse in die unten nicht benötigt-format

{"ts" : {
        "_inc" : 0,
        "_class" : "org.bson.types.BSONTimestamp"
    }}

Option 2:

doc.put("ts",new Timestamp(new Date().getTime()));

das Ergebnis :

{"ts" : ISODate("2015-01-12T05:36:43.343Z")}
InformationsquelleAutor hellojava | 2015-01-12
Schreibe einen Kommentar