mongodb-Base-Conditional operator

Source: Internet
Author: User

1. Some explanations
    • Less than: than. Less LT
    • Greater than: than. Multi-GT
    • equals: Equal E
the conditional operators in MongoDB are:
    • (>) Greater than-$GT
    • (<) less than-$lt
    • (>=) greater than or equal to-$gte
    • (<=) less than or equal to-$lte
MongoDB (>) greater than Operator-$GT

If you want to get more than 100 of the "likes" data in the "Col" collection, you can use the following command:

Db.col.find ({"likes": {$gt: 100}})

Similar to the SQL statement:

Select * from Col where likes > 100; MongoDB (>=) greater than equals operator-$gte

If you want to get data with "likes" greater than or equal to 100 in the "Col" collection, you can use the following command:

Db.col.find ({likes: {$gte: 100}})

Similar to the SQL statement:

Select * from Col where likes >=100; MongoDB (<) less than operator-$LT

If you want to get data that is less than 150 "likes" in the "Col" collection, you can use the following command:

Db.col.find ({likes: {$lt: 150}})

Similar to the SQL statement:

Select * from Col where likes < 150; MongoDB (<=) less than operator-$lte

If you want to obtain data that is less than or equal to 150 of "likes" in the "Col" collection, you can use the following command:

Db.col.find ({likes: {$lte: 150}})

Similar to the SQL statement:

Select * from Col where likes <= 150; MongoDB Use (<) and (>) queries-$lt and $GT

If you want to get "likes" in the "Col" collection greater than 100, less than 200 of the data, you can use the following command:

Db.col.find ({likes: {$lt: $, $GT: 100}})

Similar to the SQL statement:

Select * from Col where likes>100 and likes<200; MongoDB $type operator

The types that can be used in MongoDB are shown in the following table:

type Digital Notes
Double 1
String 2
Object 3
Array 4
Binary data 5
Undefined 6 is obsolete.
Object ID 7
Boolean 8
Date 9
Null 10
Regular Expression 11
Javascript 13
Symbol 14
JavaScript (with scope) 15
32-bit integer 16
Timestamp 17
64-bit integer 18
Min Key 255 Query with -1.
Max Key 127
If you want to get the data in the "Col" collection with the title String, you can use the following command: Db.col.find ({"title": {$type: 2}}) From:http://www.runoob.com/mongodb/mong Odb-operators.html

mongodb-Base-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.