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