Uploaded image for project: 'Compass '
  1. Compass
  2. COMPASS-6755

Compass interprets Date() incorrectly in queries

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.37.0
    • Affects Version/s: None
    • Component/s: Query Bar
    • None
    • Environment:
      OS:
      node.js / npm versions:
      Additional info:
    • 2
    • Not Needed

      Problem Statement/Rationale

      Compass should behave consistently with other tools such as mongosh, Charts and Node with respect to date helpers. Inconsistency leads to customer confusion and bugs (see this Slack discussion for an example)

      Steps to Reproduce

      1. Find a collection with a date field.
      2. Use Compass to filter the data using something like this:
         { createDate: { $gt: Date("2001-01-01") }}

      Expected Results

      1. Zero documents returned.
      2. This is because as per JavaScript oddities, Date("...") returns the current date as a string, ignoring the arguments.
      3. To get a working date filter, users would need to specify new Date("...") or new ISODate("...") or ISODate("...")

      Actual Results

      1. Data is filtered based on the specified date, even though this is not how Javascript works.

      Additional Notes

      Any additional information that may be useful to include.

        1. Screenshot 2023-04-20 at 11.37.31.png
          Screenshot 2023-04-20 at 11.37.31.png
          1.16 MB
        2. Screenshot 2023-04-20 at 11.39.38.png
          Screenshot 2023-04-20 at 11.39.38.png
          1005 kB
        3. Screenshot 2023-04-20 at 11.39.48.png
          Screenshot 2023-04-20 at 11.39.48.png
          1.02 MB
        4. Screenshot 2023-04-20 at 11.40.00.png
          Screenshot 2023-04-20 at 11.40.00.png
          852 kB

            Assignee:
            leroux.bodenstein@mongodb.com Le Roux Bodenstein
            Reporter:
            tom.hollander@mongodb.com Tom Hollander (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: