"MongoDB First Knowledge"-conditional operator

Source: Internet
Author: User

1, the condition >,<,>=,<= in MongoDB the wording

: $gt, <: $lt, >=: $gte, <=: $lte, <>: $ne

Specific Use method:

Db.class.find ({"filed": {$GT: Value}}) Filed>value

Db.class.find ({"filed": {$lt: Value}}) Filed<value

Db.class.find ({"filed": {$gte: Value}}) Filed>=value

Db.class.find ({"filed": {$lte: Value}}) Filed<=value

Db.class.find ({"filed": {$gt: Value, $lt: value1}}) Value1>filed>value

Db.class.find ({"filed": {$ne: 5}}) Filed<>value

Db.class.find ({"Stucount": {$gt:ten}}) Db.class.find ({"Stucount": {$gte:Ten}})
Db.class.find ({"Stucount": {$lt:ten}}) Db.class.find ({"Stucount": {$lte:Ten}})
Db.class.find ({"Stucount": {$lt:ten, $gt:5}})
Db.class.find ({"Stucount": {$ne: 5}})

2. $all Match All

This operator is similar to the SQL syntax in, but the difference is that in only one value of () is satisfied, and the $all must be
All values within [] must be met

Db.class.find ({stucount:{$all: [6,8]}}) query result is empty

Db.class.find ({stucount:{$all: [6]}) can find one, equivalent to Db.class.find ({"Stucount": 6})

3. $in contains

Is the same as the purpose of SQL standard syntax, which is to query a range of enumerated values

Db.class.find ({stucount:{$in: [6,8]}})

4. $nin does not contain

Db.class.find ({stucount:{$nin: [6,8]}})

5. Determine if a field exists

Db.class.find ({stucount:{$exists: true}})

6. Null value processing

Db.class.find ({name:null}) will query for data that does not have a name field

Db.class.find ({name:{"$in": [null], "$exists": True}}) The query result has a name field and Name=null

7, $mod to take surplus

Db.class.find ({stucount:{$mod: [7,2]}}) equals 2 for 7

"MongoDB First Knowledge"-conditional 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.