-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Querying
-
None
-
Query Optimization
In general, if there are multiple query predicates that require implicit array traversal, the behavior of the positional projection operator is undefined. For instance, should the following projection return the zeroth or first array element?
db.collection.drop(); db.collection.insert({a:[{b:1},{c:1}]}); db.collection.find({"a.b":1,"a.c":1},{"a.$":1}); // Return "a.0" element, or "a.1" element?
SERVER-14662 tracks work to make such queries return an error to the user.
However, there are cases in which this ambiguity can be resolved. Consider the following projection:
db.collection.drop(); db.collection.insert({a:[{b:1},{c:1}],d:[{e:1},{f:1}]}); db.collection.find({"a.b":1,"d.f":1}, {"a.$":1});
In this case, we can resolve the ambiguity because "a.$" matches the prefix of path "a.b" but does not match a prefix of path "d.f".
- is duplicated by
-
SERVER-30998 Update and $ operator mismatch with multiple arrays in query
- Closed
-
SERVER-53896 positional $ operator when there are two array path in query
- Closed
-
SERVER-54687 `$pull`ed index should not override query-matched index for `$(update)`
- Closed
-
SERVER-21794 Array field limitation in query document [Only one array field may appear in the query document.]
- Closed
-
SERVER-19866 Allow more than one array in query when using $ operator
- Closed
- related to
-
SERVER-27738 Positional operator ($) can choose wrong array element when there is a numerical path component
- Closed
-
SERVER-14662 Positional projection queries (and positional update ops) should fail with error if multiple arrays encountered
- Closed