$gte ISOdate function error VIA the api

Hi guys, I’m having difficulty using the $gte ISOdate function in a filter VIA the api. Can you help?

The error I get is “Invalid syntax error: TypeError: invalid character ‘I’ looking for beginning of value”

This is the end point I’m using: /endpoint/data/beta/action/find

this is the JSON:

{
   "dataSource":"Cluster0",
   "database":"v1",
   "collection":"pipedriveDeals",
   "filter":            {
         "wonDate":{
            "$gte":ISODate("2022-04-01")
         }
      }
}

Hi @spencerm - Welcome to the community :wave:

Thank you for providing the JSON used in the request.

The error I get is “Invalid syntax error: TypeError: invalid character ‘I’ looking for beginning of value”

I presume the wonDate is a date field but please correct me if I am wrong here. The Data API uses canonical MongoDB Extended JSON to encode BSON data types in request bodies. The ISODate() function is not valid MongoDB Extended JSON which is why the error is being returned.

Could you try with the following JSON instead:

{
   "dataSource":"Cluster0",
   "database":"v1",
   "collection":"pipedriveDeals",
   "filter":            {
         "wonDate":{
            "$gte": { "$date" : "2022-04-01T00:00:00Z" }
         }
      }
}

The Atlas Data API is currently in preview so there are chances the above behaviour may change.

If you’re still receiving errors, please advise of the full error message being received.

Hope this helps.

Regards,
Jason

2 Likes

Worked great, thank you!

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.