Novice MongoDB Learning---(iv) MONGODB conditional operator

Source: Internet
Author: User
Tags mongodb collection

The conditional operator is used to compare two expressions and fetch data from a MongoDB collection.

The condition operators in MongoDB are:

    • (>) Greater than-$GT
    • (<) less than-$lt
    • (>=) greater than or equal to-$gte
    • (<=) less than or equal to-$lte
> Db.new.find ({"Age": {$gt: +}}) #查找age大于22的文档 > Db.new.find ({"Age": {$lt:]}) #查找age小于22的文档 > Db.new.find ({" Age ": {$gte: $}) #查找age大于等于22的文档 > Db.new.find ({" Age ": {$lte:]}) #查找age小于等于22的文档 <pre name=" code "class=" plain ">> Db.new.find ({" Age ": {$lte: $gt:}) #查找age小于等于27, documents greater than 22.


The $type operator is based on the Bson type to retrieve the matching results in the collection.

Types that can be used in MongoDB:

Type Description Type value
Double 1
String 2
Object 3
Array 4
Binary data 5
Object ID 7
Boolean 8
Date 9
Null 10
Regular expression 11
JavaScript Code 13
Symbol 14
JavaScript Code with scope 15
32-bit integer 16
Timestamp 17
64-bit integer 18
Min Key 255
Max Key 127


>db.new.find ({"Age": {$type: +}}) #查找age为double型的所有数据




Novice MongoDB Learning---(iv) MONGODB 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.