Start a new topic

Querying ISODate stored datetimes

I saw one other related question (https://support.kinvey.com/discussion/200821163/querying-dates-with-rest-api), but the answer (that you can just use the raw date "2014-10-01") didn't work for me.



I tried using the raw date in the form:

"$gte": "2014-10-01"



And wasn't successful. Strangely, I got back everything in this case totally unfiltered. If I made it "$lte", it returned nothing.



However, when I change my format to accurately match that of the collection, the queries started working.



"$gte": "ISODate(\"2014-10-01T22:23:05.032Z\")"



Now I can run "$gte" and "$lte" queries without an problems, and they appropriately filter.



Am I doing something wrong, or is it that I actually should be querying them this way?




Hi, could this depend on the format in which you are storing your dates? Can you try querying for `_kmd.lmt` and see if you can get it to work without using ISODate?



For example, when I run the following query against my app, I get the expected result back:



```

/appdata/kid_XXX/someCollection?query={"_kmd.lmt":{"$lte":"2014-09-29"}}

```
Yea, querying like that does work. Should have thought of that, since I have queried successfully on _kmd.* in other scenarios.



I didn't write the code to add or update the data, i've just been querying it - I guess it's possible that the way it was coded it is setting the date columns incorrectly? Behind the scenes, is "_kmd.lmt" an ISODate, but the Kinvey console just shows it as a simple date for ease of interaction?
`_kmd` date values are stored as strings in the database (they are native Date objects that have been converted to string). If you need to store your dates as ISODates, then you will need to use the wrapper to search, as you've discovered.
Login or Signup to post a comment