[SERVER-65258] $dateTrunc thinks a date is a string Created: 05/Apr/22  Updated: 27/Oct/23  Resolved: 08/Apr/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 5.0.6
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Adam Crowe Assignee: Eric Sedor
Resolution: Gone away Votes: 0
Labels: aggregate, community, server
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

Since updating to MongoDB Server v5.0.6. Community Version, $dateTrunc.date thinks any date is a string. For example:

{
    $expr: {
      $lt: ["$paidDate", {
          $dateAdd: {
            startDate: {
              $dateTrunc: {
                date: new Date(), // <<=======
                unit: "day",
                binSize: 1,
                timezone: "Europe/London"
              }
            },
            unit: "day",
            amount: 1,
            timezone: "Europe/London"
          }
      }]
    }
  }

The above gives this error:

PlanExecutor error during aggregation :: caused by :: $dateTrunc requires 'date' to be a date, but got string

All existing queries via Compass and C++ are broken. If this is an official update to how this aggregate statement works, there is no updated documentation as far as I can see.



 Comments   
Comment by Eric Sedor [ 08/Apr/22 ]

Thanks for the update Adam! I'm not sure if or how that change may have affected the behavior you saw in your app.

I'm going to close this ticket but we can reopen it if you notice the problem again outside of compass.

Sincerely,
Eric

Comment by Adam Crowe [ 06/Apr/22 ]

Thank you Eric,

I have good news… Since Compass was updated yesterday to 1.31.1, this issue got resolved and the same pipeline (it's saved on my Compass) is working again. It's clearly related to this date/string issue I reported as well:

https://jira.mongodb.org/browse/COMPASS-5664

But what I don't understand is how come it's now also working via C++ in my apps? Did Compass also update the driver on my computer? I know the server wasn't updated.

Comment by Eric Sedor [ 06/Apr/22 ]

Hi adam@adamcrowe.net, I haven't been able to readily reproduce this error in MongoDB 5.0.6, but I might not have used the same aggregation pipeline stage; can you provide a complete operation that is failing in this way?

Generated at Thu Feb 08 06:02:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.