MongoDB Learning Note 03--Query expression

Source: Internet
Author: User

MongoDB Learning Note 03– query expression

Not equal to, greater than, less than

    • ! =: Db.stu.find ({name:{$ne: ' billvsme '}}) name is not ' billvsme '
    • >: Db.stu.find ({age:{$gt:18}}) older than 18
    • <: Db.stu.find ({age:{$lt:18}}) older than 18
    • >=: $GTE
    • <=: $LTE

In/not In/all

    • $in:db.goods.find (stu_id:{$in:[93001,93002,93003]}) study number 93001 or 93002 or 93003
    • $Nin:not in
    • $All: The specified content has db.stu.find ({like:{$all: [' Football ', ' Basketball '}}) students who like basketball and football

Or/and/not/nor

    • $or: or
    • $and: and Example Db.stu.find ({$and:[{age:{$gt:18}},{age:{$Lt:22}}}) age between 18 and 22
    • $not: non-
    • $Nor: If you write a condition that is not true, then return this article

Exists/mod/type

    • $exists: Example Db.find ({body:{$exists: 1}}) column with body field
    • $mod: satisfies the remainder, example db.stu.find ({stu_id:{$mod:[5,0]}) takes a number that is a multiple of 5
    • $Type: Satisfies the type example Db.stu.find ({age:{$Type:2}}) The age segment type is a column of string. 2: The expression type code specifically see http://docs.mongodb.org/manual/reference/operator/query/type/#op. _s_type

Where/regex
(Use caution, because if used, MONGO to convert binary Bson into JSON and then operate, inefficient)

    • The $where:js expression is true. Example Db.stu.find ({$where: ' this.age>18 '}) older than 18
    • $Regex: The regular expression is true. Example Db.stu.find ({name:{$regex: ' ^bill '}}) the name begins with Bill

MongoDB Learning Note 03--Query expression

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.