Mongo Isodate query in Java

I have a Mongo query executed:

query = { "dateField" : { "$gte" : ISODate('2011-11-10T07:45:32.962Z')  } }

When I execute dB. On the Mongo shell Collection. When find (query), I can retrieve the results

How do I query this using Java? I try to construct a string based on the date parameter However, in the process of building a string, it is finally passed as "Isodate ('2011-11-10t07:45:32.962z ')" instead of the quotation around Isodate ('2011-11-10t07:45:32.962z')

What is the best way to build this query using the Java API?

thank you!

Solution

Use regular Java dates – I also recommend using querybuilder:

Date d = new Date(); // or make a date out of a string...
DBObject query = QueryBuilder.start().put("dateField").greaterThanEquals(d).get();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>