Mongodb Study Notes 03. mongodb Study Notes

Source: Internet
Author: User

Mongodb Study Notes 03. mongodb Study Notes
Mongodb Study Notes 03-query expression

Not equal to, greater than, less

  • ! =: 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}) younger than 18
  • >=: $ Gte
  • <=: $ Lte

In/not in/all

  • $ In: db. goods. find (stu_id: {$ in: [93001,93002, 93003]}) Student ID: 93001, 93002, or 93003
  • $ Nin: not in
  • $ All: the specified content contains db. stu. find ({like: {$ all: ['football', 'bucketball ']}) students who like basketball and football.

Or/and/not/nor

  • $ Or: or
  • $ And: and the example db. stu. find ({$ and: [{age: {$ gt: 18 },{ age: {$ lt: 22}]}) between 18 and 22
  • $ Not: non
  • $ Nor: If none of the conditions you write are true, this one is returned.

Exists/mod/type

  • $ Exists: In the example db. find ({body :{$ exists: 1}), the column of the body field exists.
  • $ Mod: returns the remainder. For example, db. stu. find ({stu_id: {$ mod: [5, 0]}) is a multiple of 5.
  • $ Type: A string column is the age segment type that meets the type example db. stu. find ({age: {$ type: 2. 2: indicates the type code specific see http://docs.mongodb.org/manual/reference/operator/query/type/#op._S_type

Where/regex
(Use it with caution, because if you use it, mongo needs to convert binary bson into json and then perform the operation, which is inefficient)

  • $ Where: If the js expression is true, it is true. Example db. stu. find ({$ where: 'This. age> 18'}) is older than 18
  • $ Regex: the regular expression is true if it is true. Example db. stu. find ({name: {$ regex: '^ bill'}) name starting with bill

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.