Hello,
Im using mongoDb 1.32.6 and i had build a c# app in .net 6.0 to retrieve documents from MongoD.
I particular i have a simply mask for ui and i receive startDate and endDate in my api.
My schema is
Account:
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public DateTime SubscriptionDate { get; set; }
in my db i have an account with:
SubscriptionDate : “2022-01-15T00:00:00.000”
Searching this item using filter mask from Compass returning me correctly this one.
but if i create a filter with StartDate and EndDate passed from ui , i dont have anything returned.
my c# code is:
var sendDateFrom = DateTime.ParseExact(DateFrom, "yyyy-MM-ddTHH:mm:ss.fff",CultureInfo.InvariantCulture); filterDateFrom = Builders<Account>.Filter.Gte(x => x.SubscriptionDate, sendDateFrom); var sendDateTo = DateTime.ParseExact(DateTo, "yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture); filterDateTo = filterDateFrom & Builders<Account>.Filter.Lte(x => x.SubscriptionDate, DateTo);
items = await AccountCollection.Find(filterDateTo.ToList();
I send from ui :
DateFrom=2022-01-01T00:00:00.000
DateTo=2022-01-31T00:00:00.000
But item is never returned.
Thaks for support.