Hi All,
I've Googled around but not found anything that's helped me sort this out.
I have a problem querying a date field to find dates after a certain point. It seems, to me, that Morphia is generating the wrong query.
My collection and its documents were created through Morphia, and the date fields are java.util.Date objects and have been mapped by Morphia to ISODates, e.g.:
@Entity
public final class MyObject{
private java.util.Date startDate=new Date();
private java.util.Date endDate=new Date();
}
Maps to:
{
"_id" : ObjectId("4f4ce52f7efcb40f23000000"),
"startDate" : ISODate("2012-03-01T00:00:00Z"),
"endDate" : ISODate("2012-03-01T00:00:00Z"),
}
I'm then querying Mongo using code like:
myObjDao.createQuery().field("startDate").lessThanOrEq(new Date()).fetch();
which, when I log the toString() output of the query, appears to be generating a query like:
{ "startDate" : { "$lte" : { "$date" : "2012-03-02T17:15:05Z"}}}
This query returns no results from my mongo instance's interactive shell, despite there being documents where startDate is less than the supplied date.
However, this query, which I modified by hand, does return the expected results:
db.MyObject.find({ "startDate" : { "$lte" :ISODate("2012-03-02T17:05:44Z")} })
I have 2 questions:
Why does Morphia produce this query that doesn't match documents that Morphia itself mapped?
What do I need to do in order to make the query return the expected results?
Thanks in advance for any insight you can give,
Chris