My document structure in Mongo is like this :
db.user.find()
{
"_id" : ObjectId("560fa46930a8e74be720009a"),
"createdAt" : ISODate("2015-10-03T09:47:56.333Z"),
"message" : "welcome",
}
{
"_id" : ObjectId("560fa46930a8e723e720009a"),
"createdAt" : ISODate("2015-10-03T09:48:25.048Z"),
"message" : "thank you"
}
When I use the below query in my Mongo Shell to find documents between two given timestamps, i get the right result :
db.user.find({createdAt:{$gte:ISODate("2015-10-03T09:40:25.048Z"),$lte:ISODate("2015-10-03T09:50:56.333Z")}})
I am using MongoRepository with Spring in my REST service to work with the Java driver. Below is the user repository:
public interface UserRepository extends MongoRepository<User, String>
{
ArrayList<User> findbyCreatedAtBetween(Date d1, Date d2);
}
When I call make the following call in my service, it does not return any result
userRepository.findbyCreatedAtBetween(2015-10-03T09:40:25.048Z, 2015-10-03T09:50:29.006Z)
However it returns the result when I give d1 as previous day : userRepository.findbyCreatedAtBetween(2015-10-02T09:40:25.048Z, 2015-10-03T09:50:29.006Z)
Any ideas on how I can resolve this? Please help!