Compare Date Part only of BSON using LINQ

Hello Everyone,

I have just started learning and developing my first Mongo driven application. I am getting a serialization error
when trying to compare date part of a datetime property in a collection.
Both _shiftCollection.Scheduled Start and currentDate are in UTC format.
I have found numerous ways using Mongo Query, but I prefer my logic to be
strongly typed.

[What I have tried so far]

var found = await (from f in _shiftCollection.AsQueryable()
                                       where f.ScheduleStart.Date == currentDate.Date
                                       select f).CountAsync();

{document}{ScheduleStart}.Date is not supported.

Any help are greatly appreciated. TIA.

Interested in the same thing

I have the same problem, did you manage to solve it?
Can you show me how?

Hello,

Even I’m having the same issue when comparing DateTimeOffset fields. I want to compare only the date part from the DateTimeOffset. TimeSheet.FromDate is DateTimeOffset field and I’m comparing it with the DateTimeOffset field received from the user. This will have only the date. Please help.

FilterDefinition filter = Builders.Filter.Where(x => x.DocType == nameof(TimeSheetInfo)
&& x.TimeSheetInfo.UserID == userId
&&x.TimeSheetInfo.FromDate.Date == fromDate.Date
&& x.TimeSheetInfo.ToDate.Date == toDate.Date);