MongoDB Official C # driver in query condition queries usage

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.