javascriptdatetimequeryingkinvey

Kinvey query elements by date


I am trying ti query some elements from a Kinvey database in a specific time frame. I have the time of creation of the table row in Date ISO string (_kmd.lmt): _kmd.lmt

I also got my Date from and Date To as Date ISO strings. Does anyone know how could I query the collection in order to get only the entities in the given time frame?


Solution

  • You can query the records in a specific timeframe using "$gte" (greater than or equal to) and "$lte" (less than or equal to) on '_kmd.lmt' values ("kmd" means Kinvey Meta Data and "lmt" means Last Modified Time).

    Let's say, you have following timestamps and you want to get all the records modified between those 2 timestamps:

    2018-02-19T06:42:36.862Z - Mon, 19 Feb 2018 06:42:36 +00:00

    2018-07-13T04:28:38.479Z - Fri, 13 Jul 2018 04:28:38 +00:00

    Now you want to get all the records modified between above 2 timestamps i.e. modified after 19th Feb and before 13th July. Your query in the Kinvey API console should be:

    /appdata/kid_xxx/Book/?query={"$and":[{"_kmd.lmt":{"$gte": "2018-02-19T06:42:36.862Z"}}, {"_kmd.lmt":{"$lt": "2018-07-13T04:28:38.479Z"}}]}

    Thanks,

    Pranav @Kinvey