MongoDB advanced query to take the model query $mod

Source: Internet
Author: User
Http://hancang2000.i.sohu.com/blog/view/235140698.htm

$mod modulo operation to query the data of age modulo 10 equals 0
Db.student.find ({age: {$mod: [10, 1]}})
Examples are as follows:
The data for the C1 table is as follows:
> Db.c1.find ()
{"_id": ObjectId ("4fb4af85afa87dc1bed94330"), "age": 7, "length_1": 30}
{"_id": ObjectId ("4fb4af89afa87dc1bed94331"), "age": 8, "length_1": 30}
{"_id": ObjectId ("4fb4af8cafa87dc1bed94332"), "age": 6, "length_1": 30}

Query age modulo 6 equals 1 of data
> Db.c1.find ({age: {$mod: [6, 1]}})
{"_id": ObjectId ("4fb4af85afa87dc1bed94330"), "age": 7, "length_1": 30}

It can be seen that only the data of age modulo 6 equals 1 is shown, and other data that does not conform to the rules are not displayed.


The columns of the modulo query must be of number type, other types are not, and the type query that can take the modulo calculation can be useful

MongoDB advanced query to take the model query $mod

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.