Mongodb 在 Java 中的日期之间过滤
Mongodb Filters between Date in Java
请帮忙,我需要使用 java mongodb 驱动程序在日期之间进行过滤
下面是我的过滤操作,但是,在日期
之间未能 select
FindIterable<Document> documents = collection
.find(Filters.and("started", gte("2019-01-01T00:00:00.000Z"), lt("2019-03-01T00:00:00.000Z")))
因此,我想过滤日期范围。
您正在对日期的字符串表示形式执行过滤操作。
您可以尝试以下操作,以便 Spring-data 使用 $date 运算符构建您的过滤器。
Instant from = Instant.parse("2019-01-01T00:00:00.000Z");
Instant to = Instant.parse("2019-03-01T00:00:00.000Z");
FindIterable<Document> documents = collection.find(Filters.and("started", gte(from),lt(to)));
请帮忙,我需要使用 java mongodb 驱动程序在日期之间进行过滤 下面是我的过滤操作,但是,在日期
之间未能 selectFindIterable<Document> documents = collection
.find(Filters.and("started", gte("2019-01-01T00:00:00.000Z"), lt("2019-03-01T00:00:00.000Z")))
因此,我想过滤日期范围。
您正在对日期的字符串表示形式执行过滤操作。 您可以尝试以下操作,以便 Spring-data 使用 $date 运算符构建您的过滤器。
Instant from = Instant.parse("2019-01-01T00:00:00.000Z");
Instant to = Instant.parse("2019-03-01T00:00:00.000Z");
FindIterable<Document> documents = collection.find(Filters.and("started", gte(from),lt(to)));