[CSHARP-4929] Linq3Implementation: unknown operator: $dateTrunc Created: 10/Jan/24 Updated: 11/Jan/24 Resolved: 11/Jan/24 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | API |
| Affects Version/s: | 2.23.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Unknown |
| Reporter: | Sasan Pasha | Assignee: | Robert Stam |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | Bug | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Documentation Changes Summary: | 1. What would you like to communicate to the user about this feature? |
| Description |
| Comments |
| Comment by Sasan Pasha [ 11/Jan/24 ] | |||
|
hi robert@mongodb.com - thanks. let's close this ticket. I am hopeful that the Azure Cosmo team will push version 5 out. | |||
| Comment by Robert Stam [ 10/Jan/24 ] | |||
|
Using .NET local times is dangerous because it depends on the time zone of the machine the code is running on. But assuming you have the machine timezone right that looks like the right way to get the beginning midnight value. Then add 24 hours to it to get the ending midnight value. Note that if you use `.Date` (assuming you upgrade to a server version that supports it) when that executes on the server it would be comparing the `Date` in the UTC timezone, not some local time zone. So the range comparison might be the only way to write your query anyway. | |||
| Comment by Sasan Pasha [ 10/Jan/24 ] | |||
|
so something like this should work:
| |||
| Comment by Robert Stam [ 10/Jan/24 ] | |||
|
You could try comparing ranges. For example, replace
with
Make sure that all dates are stored in UTC in the database (MongoDB requires that) and that your comparison values are in UTC also. | |||
| Comment by Sasan Pasha [ 10/Jan/24 ] | |||
|
this is for the latest server version 4.2 on Azure CosmoDB - if this only works for Server Version 5, do you know a way to re-write the query so it works for 4.2? | |||
| Comment by Robert Stam [ 10/Jan/24 ] | |||
|
What server version are you using? Note that the `$dateTrunc` operator was added in server version 5.0. If you are using an older server version then you can't use this functionality. | |||
| Comment by Sasan Pasha [ 10/Jan/24 ] | |||
|
The same applies to Date.Year, Date.Month, Date.Day comparisons. | |||
| Comment by PM Bot [ 10/Jan/24 ] | |||
|
Hi sasan.pasha@gmail.com, thank you for reporting this issue! The team will look into it and get back to you soon. |