Life Lei dog MongoDB----MONGODB---3---comparison operator

Source: Internet
Author: User

$lt < less than

$lte <= less than and equal smaller than or equal to

$GT > greater than greater than

$gte >= greanter than and equal greater than or equal to

$ne! = Not equal range

The simple usage is as follows:

Demand:

Users less than 30 are queried:

Db. user. Find ({age:{$lt:}},{_id:0});

Requirements: 18-25-year-old users are queried

Db. user. Find ({age:{$gte:$lte:)});

Note: Here is a feature that is for the age of the key to query, can be in the object of the comparison operator, write multiple, it is to meet the conditions therein.

Demand:

Find a 18-25-year-old male and user

Db. user. Find ({$and:[{sex: ' Male '},{age:{$gte: $lte:]}]},{_id:0 });

Demand:

Check with 18 or 25-year-old users

Db. user. Find ({$or:[age:18],[age:22] },{_id:0});

Here we have a feature, that is, for age to compare, if this is the case, we can also use $in to achieve the same effect

Db. user. Find ({age:{$in:[18,22]}},{_id:0});

Search for a person who is gender-or between 18-25 years of age:

Db. user. Find ({$or:[{sex: ' Male '},{age:{$gte: $lte:]}]},{_id:0 })

Non-operation, which is our common inversion:

Querying users who are not 18-22

Db. user. Find ({age:{$not: {$gte:$lte:}}},{_id:0})

Life Lei dog MongoDB----MONGODB---3---comparison 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.