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命令,使用此寫法能夠自由拼接參數mongodb
//判斷時間範圍,單位:秒this
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);