我正在尝试使用以下方式在 MongoDB 中插入日期:
collection.insert(Json.obj("user"->"abc", "joined_date" -> DateTime.now))
在数据库中:
{
"_id" : ObjectId("5865d99718969bca6a09450f"),
"user" : "abc",
"joined_date" : NumberLong("1483069847066")
}
这里的问题是日期以长毫秒格式存储在数据库中,但我想要的是它以 ISO 日期格式存储。
我曾尝试在 MongoShell 中保留相同的数据db.example.insert({user:"abc", joined_date:new Date()})
,结果如下:
{
"_id" : ObjectId("5865d838a4f98c5bb83b1eb8"),
"user" : "abc",
"joined_date" : ISODate("2016-12-30T03:44:56.824Z")
}
那么,如何使用 ReactiveMongo 在数据库中以 ISODate 格式存储日期?