[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.