Multikey Index bounds in MongoDB explains $elemmatch

Source: Internet
Author: User
Tags mongodb query

First, let's talk about the use of $elemMatch:

{ _id: 1, results: [[+ ]]

{ _id: 2, results: [[], +/- ] }

$elemMatch is that at least one element in the array matching document satisfies all the conditions in $elemmatch, for example:

db. Scores. Find ({results: { $elemMatch : { $gte : 80  $lt : 85 } } Span class= "p" >}) 

query result:

{ "_id" : 1, "Results" : [[A] [[+ ]]

To explain it (Multikey Index Bounds):
during a query, the scan range of the index defines a partial index in order to search when more than one index (condition) predicates exists: MongoDBwill attempt to merge the boundaries of these (conditions) predicates, or merge them by the method of intersection
Either by combining the method, in order to produce a relatively small scanning range. given an indexed array field, consider that in one query, multiple (conditional) predicates are specified in an array and Multikey index can be used.
if the $elemMatch has more than one Predicates, MongoDB merges the boundaries of Multikey index. Therefore, there will be $elemmatch that matches at least one element of the array in the document satisfies all the conditions in $elemmatch.

Continue with the above example, one by one the bounds of the conditional boundary:
A boundary greater than or equal to ($gte: 80) is [80,inf];
Less than($LT: 85)the boundary for [-inf,85].
Because of the use of the $Elemmatch organization of multiple conditional queries, MongoDB query boundary is results:[[80,85)].







Multikey Index bounds in MongoDB explains $elemmatch

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.