Query.all ("name", "a", "B"), or//through multiple elements to match the array Query.and (Query.eq ("name", "a"), Query.eq ("title", "T"));//satisfy multiple conditions at the same time query.eq ("name", "a");//equals Query.exists ("type", true);//Determines whether the key value exists query.gt ("value", 2);//greater Than > Query.gte ("value", 3);//greater than or equal to >= query.in ("name", "a", "B");//Includes all values specified, you can specify different types of conditions and values query.lt ("value", 9);//Less than < Query.lte ("value", 8),///less than or equal to <= query.mod ("Value", 3, 1);//Divide the query value by the first given value, If the remainder equals the second given value, the result is returned query.ne ("name", "C"),//Not equal to Query.nor (array),//not including the value in the array query.not ("name");// The element condition statement query.notin ("name", "a", 2);//Returns a document that does not match all the conditions in the array query.or (Query.eq ("name", "a"), Query.eq ("title", "T"));//satisfies one of the conditions query.size ("name", 2);//The length of the given key Query.type ("_id", bsontype.objectid);//The type of the given key Query.where (bsonjavascript);//execute JavaScript query.matches ("Title", str);//fuzzy query equivalent to SQL in like--STR can contain regular expressions
Example:
using (var database = new Server.mongodatabaseserver ()) {MONGOCOLLECTION&L T bsondocument> MC = database. Getcollection<bsondocument> ("Newslist"); DateTime qtime = DateTime.Now; var query = Query.and (Query.gte ("Publishdate", StartDate), Query.lte ("Publishdate", EndDate), Query.eq ("NewsSource", " Kompas ")); foreach (Bsondocument emp in MC. Find (query) {Long newsId = emp["NewsId"]. AsInt64; string title = emp["Newstitle"]. asstring; Console.WriteLine ("Query end: News ID" + newsId + "----Title:" + title); } DateTime etime = DateTime.Now; TimeSpan ts = etime. Subtract (Qtime); String stime = ts. Totalmilliseconds.tostring (); Console.foregroundcolor = consolecolor.red; Console.WriteLine ("Toatal use" + stime + "Ms to Query"); }
MongoDB official C # driver query criteria for querying usage