I have documents that I can find using the Data API.
> % curl --silent --location --request POST 'https://data.mongodb-api.com/app/data-ppqjw/endpoint/data/beta/action/find' --header 'Content-Type: application/json' --header 'Access-Control-Request-Headers: *' --header 'api-key: <api-key>' --data-raw '{"collection":"db-stats-historical","database":"jdi-admin","dataSource":"Cluster0","filter": { "State": "CA", "County": "Siskiyou", "Race": "White", "Age": "15-24", "Gender": "Female" }, "limit": 100}' | jq .
{
"documents": [
{
"_id": "626303f2452680844dfb8a77",
"Date": "2020-02-17T00:00:00.000Z",
"Population": 0,
"State": "CA",
"County": "Siskiyou",
}, {
"_id": "626303f2452680844dfba711",
"Date": "2020-02-17T00:00:00.000Z",
"Population": 0,
"State": "CA",
"County": "Siskiyou",
},...
]
}
So, in order to fetch for this data, I have to do a filter like:
{
"State": "CA",
"County": "Siskiyou",
"Date": { "$date": {"$numberLong": "1581897600000" }
}
So we think of the dates above as being like “2020-02-17”. But then we see “2020-02-17T00:00:00.000Z” in the database? And then we have to translate that to time-millis to do a query that retrieves this same document? Really?
Oh, yes. And we have to translate “2020-02-17” in PST to “2020-02-16 16:00”. Or is it “2020-02-16 17:00”. And then translate that to time-millis? :–)
Is there a better way to filter on date values in the Data API?