An error occurred while saving the commentGianluca Nitti commented
Thanks for the clarification.
Yes, support for constant expressions would be enough for my use case.
In fact, what I need is exactly to $dateTrunc a date that comes from user input. I could do it in my application code, however the application is structured in a way where I have various pipelines saved as JSON with "placeholders" where parameters coming from the end user are replaced right before sending the pipeline to MongoDB for execution; these parameters are not always dates and when they are they don't always need to be truncated, so having the ability to truncate them directly in the pipeline would result in cleaner code on the application side since I wouldn't have to save somewhere else the information on which parameters must be "preprocessed" and handle them separately.
So, when the pipeline is sent to MongoDB it would contain an expression exactly like the one you posted, with two $dateTrunc operations with constant dates as input.Gianluca Nitti shared this idea ·