Interaction of "MongoDB" arrays and Range queries

Source: Internet
Author: User

A scalar (non-array element) in the document must match each statement in the query condition. For example, if you use {"X": {"$GT": Ten, "$lt": 20} The query will only match documents with the value of "X" key greater than or equal to 10 and less than or equal to 20. However, if the X field of a document is an array, the document returns if an element of the X's key matches any of the query's statements. Examples are as follows:

Now you want to find the value of age in all documents between 10 and 20:

It can be seen from:

1. You can use ' $elemMatch ' to ask a MONGODB colleague to use two statements in a query condition to compare to an array element, and the label does not match a non-array element.

2. Be sure to add an index to the field when using Min and Max, or add an error.

Interaction of "MongoDB" arrays and Range queries

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.