首页 文章

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

提问于
浏览 546
-2

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

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

2 回答

  • 0

    你可以这样做:

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

    你尝试过什么吗?

    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();
    

    使用的名称虽然:)

相关问题