[MongoDB] interaction between arrays and range queries, mongodb array queries

Source: Internet
Author: User

[MongoDB] interaction between arrays and range queries, mongodb array queries

The scalar (non-array element) in the document must match each statement in the query condition. For example, if {"x": {"$ gt": 10, "$ lt": 20} is used for query, only documents with the "X" key value greater than or equal to 10 and less than or equal to 20 will be matched. However, if the x field of a document is an array, if an element of the x key matches any query statement, this document will return. For example:

 

Now we want to find all documents whose age value is between 10 and 20:

 

We can see that:

1. You can use '$ elemmatch' to ask Mongodb colleagues to use two statements in the query condition to compare with an array element, and the label does not match non-array elements.

2. When using min and max, you must add the index for this field. Otherwise, an error is returned.

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.