Is there any way to match MongoDB date using C#.net

Viewed 22

I am using the below code to get data based on PersonID and date but getting empty arrays[].What could be wrong here, please help.

public static PipeLineDefinition<Journey, JourneyActions> FilterJourney(UserJourney request)
    => new[]
    { new BsonDocument("$match",new BsonDocument("PersonID",request.PersonID.value)),
      new BsonDocument("$match",new BsonDocument{
          {"visitDate",new BsonDocument{
             {"gt",request.visitDate.AddDays(-1)},
              {"lt",request.visitDate.AddDays(1)}
           }}} )

    };

The format of date in MongoDB is "2022-04-11T00:00:00:000+00:00". I tried to hard code this date in the code but still getting empty arrays.

1 Answers

Make use Date.tryparse(request.visitDate.AddDays(-1)) and it will work.

Related