var document = new BsonDocument{ { "$where","this.StarTime!=this.EndTime"}, { "Closed",1}, { "StarTime",new BsonDocument("$gte",request.Stime)}, { "EndTime",new BsonDocument("$lte",request.Etime)}, { "TotalSecond",new BsonDocument(para,request.TotalMin * 60)} }; var list= collection.Find(document);
其中this不能省略,写法同mongodb命令,使用此写法可以自由拼接参数
//判断时间范围,单位:秒
var document = new BsonDocument{ { "$where","this.StarTime-this.EndTime>10"}, { "Closed",1}, { "StarTime",new BsonDocument("$gte",request.Stime)}, { "EndTime",new BsonDocument("$lte",request.Etime)}, { "TotalSecond",new BsonDocument(para,request.TotalMin * 60)} }; var list= collection.Find(document);