dj-nitehawk / MongoDB.Entities

A data access library for MongoDB with an elegant api, LINQ support and built-in entity relationship management
https://mongodb-entities.com
MIT License
547 stars 70 forks source link

return zero #234

Closed kingsanu closed 3 days ago

kingsanu commented 3 days ago

i trying to filter only date except time, but it return me 0

var orders2 = DB.Queryable<MongoOrders>().Where(x => x.DateTill12AM.Date == parsedDate.Date).ToList();
dj-nitehawk commented 3 days ago

mongo server doesn't support equality comparison on just the date component of a stored utc isodate. so have to do a range query something like the following:

var results = await DB.Find<MyDocument>()
                      .Match(doc => doc.MyDate >= startOfDay && doc.MyDate < endOfDay)
                      .ExecuteAsync();
kingsanu commented 2 days ago

great thank you but is there any option that date always store in localtimezone, it make more problem with isodate, i saved 27 aug but it return 26 aug, and i can't parse always ToLocalTime()

in short ICreatedOn or any datetime stored in isodate i tried to store by ToLocalTime() but still return me isodate

dj-nitehawk commented 2 days ago

that is the default behavior of the mongodb server and the official driver and not something related to this library. besides, the best approach to future proof your app is to store dates in utc and convert to and from required time zones with your app code. most of the time, i use the nodatime library.