mongodb-js / charts-embed-sdk

The easiest way to embed MongoDB Charts visualisations into your web app
https://docs.mongodb.com/charts/master/embedding-charts-sdk/
Apache License 2.0
43 stars 31 forks source link

How to filter using date or datetime #25

Closed ppascualv closed 3 years ago

ppascualv commented 3 years ago

I'm trying to use DateTime filter and it is are returning an empty chart I'm assuming the filter is not well interpreted by Mongo.

Code examples of what I already tried:

startDate = moment()

filter = { created_at: {
      $gte: startDate.toISOString()
}}
startDate = moment()

filter = {created_at: {
      ISODate('${endDate.format("YYYY-MM-DD")}')
}}
tomhollander commented 3 years ago

You should be able to use regular JavaScript Date objects. You don't need to format then yourself.

kristinamongo commented 3 years ago

An example of a filter using a JS date object:

const filter = { created_at: { $gte: new Date('2021-03-14') } };

This filter will return all documents that have created_at date of 14th of March 2021 or later.

ppascualv commented 3 years ago

Thanks!