0

I am just stucked in a problem, a great thanks in advance. I am working in spring mvc application, that works good on local host but after deployment when I hit a get request for fetching some mongo data it returns null. I double checked the mongo db, it is same as in localhost and in server, version is also same and when I am executing the query on mongo shell and I got data. I am confused why the get request is not working if data is present and query generated in get request is same as we execute in mongo shell.

The query generated in system.profile is :

"$and" : [{"batchId" : {"$eq":"56d54d4e975a318a8d98a10a"}},{"date" : {"$eq" : ISODate("2017-05-09T07:00:00Z")}},{"userType" : {"$eq" : 1}}]

While the query I excuted in shell is:

 db.attendance.find({ "$and" : [{"batchId" : {"$eq":"56d54d4e975a318a8d98a10a"}},{"date" : {"$eq" : ISODate("2017-05-09T07:00:00Z")}},{"userType" : {"$eq" : 1}}]})
Kohei TAMURA
  • 4,970
  • 7
  • 25
  • 49
kalyani
  • 23
  • 4
  • Is it the query that is null or is your `MongoClient` not properly initiated? You'll need to provide more info. – Tan Kim Loong Jun 20 '17 at 02:32
  • You are trying to search for an "exact value" of a date which most likely does not actually exist. You really want the "range" of dates for a particular day to get all the timestamp values in between. As in `"date": { $gte" : ISODate("2017-05-09T07:00:00Z"), "$lt": ISODate("2017-05-10T07:00:00Z") }`. That is how you select "one day". Also note that you are providing local times and not UTC, so you might need to establish your date input variables as UTC instead, so you don't get the 7 hour offset. – Neil Lunn Jun 20 '17 at 05:49

0 Answers0