From your question I understand that you ask for a way to create date queries in MongoDB and how would your write that query in Morphia
The Cookbook for date queries can be found here.
As pointed in the above post, you should use a range query for this.
In MongoDB's shell, for your first query, you would write it like this:
// hope I got the date part right XD
db.posts.find({created: {$lt: new Date().getDate() - 2}});
For range queries morphia has 2 ways:
- using the filter method
- using directly the comparator methods.
So the first query would become something like this:
myObjDao.createQuery().field("created").lessThan(new Date(System.currentTimeMillis() - 2 * 24 * 3600 * 1000 )).fetch();