Bob Kuhar
Bob Kuhar

Reputation: 11100

How to I write a "Date Between" query in the Mongo Java Driver?

I have a query that works like a champ through the Javascript shell...

db.profiles.find(
  { "createdOn" :
    { $gte : ISODate( '2013-04-01T00:00:00.000Z' ),
      $lt : ISODate( '2013-04-02T00:00:00.000Z' )
    }
  }
)

. How do I do this through the Java driver?

Upvotes: 0

Views: 1991

Answers (1)

assylias
assylias

Reputation: 328568

Have you tried something like:

DBObject condition = new BasicDBObject(2);
condition.put("$gte", startDate);
condition.put("$lt", endDate);
Iterable<DBObject> result = collection.find(new BasicDBObject("createdOn", condition));

Upvotes: 1

Related Questions