mongodb--operator

Source: Internet
Author: User
Tags array length prev

    • $gt -->
    • $lt --<
    • $gte -->=
    • $lte --<=

  • $all is similar to in, the difference is that all the values in [] must be met
  • $exists Field exists Db.sun.find ({"Age": {"$exists": True}}) queries for data that has an age field, null field value is NULL, and no query field data is listed. Only the data with the value NULL is queried Db.sun.find ({"Age": {"$in": [null], "$exists": True}}) This field exists and the value is null
  • $mod modulo operation (equivalent to C #% take-rest operation 10%3==1) Db.sun.find ({"Age": {$mod: [10,0]}}) field to 10 modulo equals 0 data
  • $ne is not equal to Db.sun.find ({"Age": {"$ne": 10}}) querying fields with an age field that is not equal to 10
  • $in contains the operation, equivalent to the SQL in operation Db.sun.find ({"name": {"$in": ["Sun", "2", "Sunxueyang"]}})
  • $nin does not contain an action, equivalent to SQL not in operation Db.sun.find ({"name": {"$nin": ["Sun", "2", "Sunxueyang"]}})
  • $size length judgment. Db.sun.find ({"like": {"$size": 2}}) get data like array length is 2
  • /Regular Expressions/queries can be processed directly using regular, sun/=sun%/sun/=%sun%/sun=%sun
  • $where can be executed by passing in the query condition. Db.sun.find ({"$where": "This.age>1"}) this represents the current row data at execution time
  • count () gets the number of queries
  • Skip () take 10th data
  • limit (5) the query out of the 5 conditions equal to the top 5, and skip combination can become a paging query, Db.sun.find (). Skip (10) If every page 10, this is the 2nd page of data to fetch, Db.sun.find (). Skip ((2-1) *n). Limit (N). Sort (field:1) sorting, when the amount of data is relatively large, performance is relatively low, it is recommended to create a self-increment field, the minimum number of the self-increment field is calculated when paging, and then use the limit
    • Sort () sort function sorted ({age:1,name:-1}), according to the sequence of the age, according to the reverse order of the name, note: If the column is in sequence, the data that does not exist in the field is preceded
    • The same property, the value type is not the same, the sort order is:
Minimum value
Null
Numbers (shaping, long Integer, double-precision)
String
objects, documents
Array
Binary data
Object ID
Boolean type
Date type
Time stamp
Regular expressions
Maximum Value

    • distinct () Db.runcommand ({"distinct": "Table name", "key": "Specified column"}) for the specified field is equivalent to Db.sun.distinct ("name")

    • Group () Group
Db.gtb.group ({key:{age:1}, cond:{age:{$gt: 2}, Reduce:function () {}, initial:{}}) is  equivalent to  select Age,count (1) From GTB GROUP by age  Db.posts.group ({"key": {"Day": true},/////Based on key, the result shows key "initial": {"tags": {}},//Initialize the displayed TA GS Document Object "$reduce": Function (Doc, prev) {//doc is the current line object, Prev object for initial build for   (i in doc.tags) {//traverse the current line's tags array     if (d Oc.tags[i] in prev.tags) {//If the data inside the tags array of the current line exists in the object that is being built, then statistics +1, otherwise initialized to 1     //"Prev" represents the cumulative state       of the "accumulator document" prev.tags[doc.tags[i]]++;     }     else     {       Prev.tags[doc.tags[i]] = 1;     }}  , "Finalize": function (prev) {//For each time the reduce ends, Manipulating the accumulator document for    (i in prev.tags)//Preserving data    {      if (prev.tags[i]<2)      {        Delete prev.tags) of the current accumulator greater than 2 [i];      }    } }}) is the same as, first, according to the day time group, and then the group after the tags array content to be counted,


    • Next () cursor operation
var cur =db.posts.find (); Currently querying the collection object while (Cur.hasnext ()) {print (Cur.next ())///means printing the current cursor object} is equivalent to Cur.foreach (function (ITM) {print (ITM)}), The difference is cur.next () is an object entity, and ITM is an object reference.



    • find () query, the Find query in the form of objects, and there is no first time to query, but wait for a real query to go to the retrieval. For example:
        var res=db.posts.find ()  //currently does not actually execute query  res.hasnext ()//At this time only real departure query

mongodb--operator

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.