string name="abc";
var wheres = Builders<T>.Filter.Exists("unique_id");
// 邏輯或 | 邏輯與& 根據實際邏輯判斷
if (!string.IsNullOrEmpty(name))
wheres = wheres & (Builders<T>.Filter.Regex("name", new BsonRegularExpression(new Regex(name, RegexOptions.IgnoreCase)))) | Builders<T>.Filter.Regex("other.name", new BsonRegularExpression(name));
Filter.All("name", "a", "b");//通過多個元素來匹配數組
Filter.And(Query.EQ("name", "a"), Query.EQ("title", "t"));//同時滿足多個條件
Filter.EQ("name", "a");//等於
Filter.Exists("type", true);//判斷鍵值是否存在
Filter.GT("value", 2);//大於>
Filter.GTE("value", 3);//大於等於>=
Filter.In("name", "a", "b");//包括指定的所有值,可以指定不同類型的條件和值
Filter.LT("value", 9);//小於<
Filter.LTE("value", 8);//小於等於<=
Filter.Mod("value", 3, 1);//將查詢值除以第一個給定值,若餘數等於第二個給定值則返回該結果
Filter.NE("name", "c");//不等於
Filter.Nor(Array);//不包括數組中的值
Filter.Not("name");//元素條件語句
Filter.NotIn("name", "a", 2);//返回與數組中所有條件都不匹配的文檔
Filter.Or(Query.EQ("name", "a"), Query.EQ("title", "t"));//滿足其中一個條件
Filter.Size("name", 2);//給定鍵的長度
Filter.Type("_id", BsonType.ObjectId );//給定鍵的類型
Filter.Where(BsonJavaScript);//執行JavaScript
Filter.Matches("Title",str);//模糊查詢 相當於sql中like -- str可包含正則表達式