Search code examples
c#mongodbasp.net-mvc-4

how to convert the below MongoDB query to c#?


how to convert the below MongoDB command in c#?

db.Report.find({DateAndTime:{$gt: ISODate("2014-11-13T18:43:33.868Z"),$lt:ISODate("2014-11-14T23:43:33.868Z")}})

Solution

  • You can do something like this:

    public List<Report> FindRports()
    {
        var reportContext = new ReportContext();
        var builder = Builders<Reprot>.Filter;
        var filter = builder.Gt(x => x.GeneratedAtUtc, new DateTime(2014, 11, 13, 18, 43 ,33 ,868)) 
                   & builder.Lt(x => x.GeneratedAtUtc, new DateTime(2014, 11, 14, 18, 43, 33, 868));
        var result = reportContext.ReportCollection.Find(filter).ToList();
        return result;
    }