Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用MongoDB Java按lastprocessedTime进行查询_Java_Mongodb_Mongodb Java - Fatal编程技术网

无法使用MongoDB Java按lastprocessedTime进行查询

无法使用MongoDB Java按lastprocessedTime进行查询,java,mongodb,mongodb-java,Java,Mongodb,Mongodb Java,我是MongoDB新手,请帮我获取这段代码返回数据。 String dateString=“Sun Jul 05 00:00:00 IST 2020” 注意:mongo shell查询在ISODate:db.xxx.find({“lastProcessedTime”:{“$gte”:ISODate(“2020-07-05 00:00:00”)})下运行良好。您需要使用如下所示的正确格式模式来解析日期字符串“Sun Jul 05 00:00:00 IST 2020”。我正在使用java.text.

我是MongoDB新手,请帮我获取这段代码返回数据。 String dateString=“Sun Jul 05 00:00:00 IST 2020”


注意:mongo shell查询在ISODate:db.xxx.find({“lastProcessedTime”:{“$gte”:ISODate(“2020-07-05 00:00:00”)})下运行良好。

您需要使用如下所示的正确格式模式来解析日期字符串
“Sun Jul 05 00:00:00 IST 2020”
。我正在使用
java.text.simpleDataFormat
(您也可以尝试
java.time
API)

我使用MongoDB Java驱动程序v3.12 API作为查询代码:

MongoCursor<Document> cursor = collection.find(Filters.gte("lastProcessedTime", date)).iterator();

while (cursor.hasNext()) {
    Document doc = (Document) cursor.next();
    System.out.println(doc);
}
MongoCursor=collection.find(Filters.gte(“lastProcessedTime”,date)).iterator();
while(cursor.hasNext()){
Document doc=(Document)cursor.next();
系统输出打印项次(doc);
}
String dateStr = "Sat Jul 04 00:00:00 IST 2020";
DateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
Date date = dateFormat.parse(dateStr);
MongoCursor<Document> cursor = collection.find(Filters.gte("lastProcessedTime", date)).iterator();

while (cursor.hasNext()) {
    Document doc = (Document) cursor.next();
    System.out.println(doc);
}