如何在c#中转换下面的mongodb命令?

如何在c#中转换下面的 MangoDB 命令?

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

回答(2)

2 years ago

你可以这样做:

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;
}

2 years ago

你尝试过什么吗?

var greaterThen = new DateTime(2014,11,13) //or as you want
var smallerThen = new DateTime(2014,11,13) //or as you want
var report = db.Report.Where(r => r.Created > greaterThen && r.Created < smallerThen).ToList();

使用的名称虽然:)