My application is a spring boot REST API which is interacting with MongoDB using the MongoTemplate.
We are observing a delay in response time for retrieval operations when the query is having a date range.
In our analysis, we noticed that the query when we ran using Mongo shell it is taking 20milliSeconds while the same query through java API it is more than 9 seconds.
Only difference is that Mongoshell accepts the date formart as ISODate in query while MongoTemplate in java is framing EPOCH date.
The date is stored in ISODate format in MongoDB Collection documents
The query generated from java side as follows
{ “rowCreationDate” : { “$gte” : { “$date” : 1566345601049 }, “$lte” : { “$date” : 1598054401049 } } }
Mongo shell query
{ “rowCreationDate” : { “$gte” : ISODate(“2018-08-07T14:13:10.979Z”), “$lte” : ISODate(“2020-09-07T14:13:10.980Z”) } }
MongoDB version: 4.0.18
How can we introduce ISODate in query generated from Java using Mongotemplate? Will it helps to improve the retieval time?