【发布时间】:2016-12-23 20:17:12
【问题描述】:
这是我在 mongodb 中的收藏
{
"_id" : ObjectId("58553f0318e2893724222cdb"),
"name" : "abc",
"datetime" : ISODate("2017-01-23T10:50:50.574Z")
}
{
"_id" : ObjectId("58553f0318e2893724222cdb"),
"name" : "abc",
"datetime" : ISODate("2016-01-23T10:50:50.574Z")
}
{
"_id" : ObjectId("58553f0318e2893724222cdb"),
"name" : "abc",
"datetime" : ISODate("2015-01-23T10:50:50.574Z")
}
我正在使用 java 驱动程序查询这个集合,如下所示,
MongoCollection<Document> collection = db.getCollection("collection");
Document DateFilter = new Document("datetime", new Document("$gt",new Date()));
int count = collection.find(DateFilter).size();
count 返回 0。(它应该返回 1) 无论我使用什么范围,总是返回 0
DateFilter.toJson(),返回如下
{ "datetime" : { "$gte" : { "$date" : 1482524040000 } } }
当我使用上面的 json 作为过滤器直接查询 mongodb shell 时,没有返回任何内容。
当我使用下面的 json 作为过滤器时,返回正确的结果
{"datetime" : { "$gt" : ISODate("2016-12-24T20:56:05.423Z") } }
【问题讨论】:
-
为什么所有文件都有相同的id?
标签: mongodb