Date query in Postman

Hello everyone,
I have a collection that I want to query on dates, and I need to pass them

Under mongo compass in filter I pass { "date": { $gt:ISODate('2022-06-05') } } and it works, but I can’t convert it to work with postman

{
     "dataSource": "{{DATA_SOURCE}}",
     "database": "{{DATABASE}}",
     "collection": "{{COLLECTION}}",
     "filter": {
         "date": {"$gt": ('2022-06-05')}
     }
}

Hi @Cedric_95fr - Welcome to the community :slight_smile:

Do the details and examples on this post help? In saying so, I believe your filter should be something like the following example:

"filter": {
         "date": 
            {"$gt": {"$date": "2022-06-05T00:00:00Z"}}
     }

Please test this out on a test environment and see if it helps in your case.

If not, could you provide sample documents within your database and your expected output?

Regards,
Jason

Hi Jason , do you know how to query with a regular expresion?
I tried this { “area” : /. no se que. / } , it works in Compas .
but when I tried with the data api I needed to put quotes
as this : {“area” : “/. no se que. /”} and this didn’t work

Regards

Hi,

I’ve signed up because I ran into the same issue.

The filter works for regular collections, but time series collections force you to store the time index as a BSON format. I can’t really replicate what JS is doing with the ISODate()-function by hand. I’ve tried all varaiations i could find, timestamps, EJSON formats, regular JSON formats (both found here: ), the suggestion from Jason, nothing works.

I couldn’t find a way to replicate what the ISODate() function does to a string either (I’m no Web / JS dev). Is this a limitation of the data API or am I doing something wrong here?

Tl;dr: I can filter regular collections just by string input, time series collections on the other hand seem to demand BSON timestamps that I can’t replicate with the given data API. Pls Help. :frowning:

Hi @Jon_Stau the above linked solution from @Jason_Tran should work for you. Time-series collections require the timeField to be stored as a BSONDate type. When using the Data API to query a time-series collection or any other collection the syntax must be valid MongoDB Extended JSON so the ISODate function is not recognized and the DataAPI query should the $date operator to product the same result. For example for a timeField using the field name date:

    "filter":  {"date": {"$gte": { "$date": "2022-08-01T00:00:00Z" } 
        }
    }
}'