0

我正在尝试在 MongoDB 中格式化我的日期,以便它不是字符串,而是每条记录上的内部 BSON 日期,这样我就可以做 TTL 的事情。我正在使用 Java 驱动程序和新的 Date() 方法,但日期在结果记录中一直显示为字符串。有任何想法吗?

        Date now = new Date();
        BasicDBObject doc = new BasicDBObject("keyword", keyword).
            append("user", user).
            append("icon", picture).
            append("message", message).
            append("location", location).
            append("media", media).
            append("mediatype", mediatype).
            append("link", link).
            append("mood", mood).
            append("count", 1).
            append("geo", new BasicDBObject("lon", lon).append("lat", lat)).
            append("date", now);
        coll.insert(doc);

..

Creates record with date as a string: "date" : "Wed Nov 06 2013 18:35:25 GMT-0500 (EST)"
4

1 回答 1

0

For doing TTL there is support available out of the box from MongoDB
When you use java.util.Date it should result in the ISODate in Mongo. Refer this .

于 2013-11-06T23:50:58.987 回答