c# Mongodb两个字段不相等 MongoDB原生查询

时间:2021-09-26 11:09:54
var document = new BsonDocument{
{ "$where","this.StarTime!=this.EndTime"},
{ "Closed",},
{ "StarTime",new BsonDocument("$gte",request.Stime)},
{ "EndTime",new BsonDocument("$lte",request.Etime)},
{ "TotalSecond",new BsonDocument(para,request.TotalMin * )}
};
var list= collection.Find(document);

其中this不能省略,写法同mongodb命令,使用此写法可以*拼接参数

//判断时间范围,单位:秒

var document = new BsonDocument{
{ "$where","this.StarTime-this.EndTime>10"},
{ "Closed",},
{ "StarTime",new BsonDocument("$gte",request.Stime)},
{ "EndTime",new BsonDocument("$lte",request.Etime)},
{ "TotalSecond",new BsonDocument(para,request.TotalMin * )}
};
var list= collection.Find(document);