一、查询
var doc = new Document();1、模糊查询var reg = new MongoRegex(".*" + qry.名称 + ".*", MongoRegexOption.IgnoreCase);doc["Name"] = reg;mongodb
{"Name":/CZ/} 不要引号
2、IN查询var docIn = new Document("$in", qry.名称.Split(','));doc["Name"] = docIn;3、等值查询doc["Name"] = qry.名称;4、介于时间值之间Document docLessGreater = new Document();//参数doc.Insert("$gte", startTime, 0);//大于开始时间doc.Insert("$lte", endTime, 1);//小于结束时间doc["CollectTime"] = docLessGreater;
5.Or查询
var docInT = new Document();
docInT["Type"] = new MongoRegex(".*" + "A" + ".*", MongoRegexOption.None); var docInT2 = new Document(); docInT2["Type"] = new MongoRegex(".*" + "B" + ".*", MongoRegexOption.None); List<Document> lst = new List<Document>(); lst.Add(docInT); lst.Add(docInT2); doc["$or"] = lst;