charts-embed-sdk icon indicating copy to clipboard operation
charts-embed-sdk copied to clipboard

Date filter doesn't work when using SDK

Open thomasViabeez opened this issue 1 year ago • 1 comments

Bug description :

When applying date filter to a date property on createChart method, resulted charts are incorrect (Zeros or blank charts).

Here is the filter I'm passing in the createChart method :

filter : { dateStart: new Date('2024-03-19') }

This filter should result in one document in the target collection and the property dateStart is recognized as Date type in either mongoDB charts web UI and in MongoDB Compass.

Screenshot from 2024-03-20 10-34-47

Expected behavior :

When passing date based filter to the createChart method, the filter should apply correctly and the display data should reflect the result of the same query made via compass or MongoDB charts UI.

Here is a post with further explanations

thomasViabeez avatar Mar 20 '24 12:03 thomasViabeez

Hi @thomasViabeez

I think the problem here might be that the date does not match exactly because of the minutes in the date. If you want an exact match you need to see what the the date value in the mdb document that you are targeting. Like for example, this filter works for a single date document from my db collection:

filter: { dateStart: new Date("2024-03-19T16:00:00.000")}

If you do not want to put precise dates, you can use a 24 hour range:

filter: {
  $gte: new Date("2024-03-19T00:00:00.000"),
  $lte: new Date("2024-03-19T23:59:59.999")
}

I hope that helps

kristinamongo avatar Mar 21 '24 03:03 kristinamongo

Closing this as there is no activity and there should be no issue around date filters in the SDK. More details in the community post.

kristinamongo avatar Jul 15 '24 00:07 kristinamongo