Does MongoDB lookup stage in aggregation support covered query optimization? For example, with pipeline
db.MyColl.aggregate([
{$lookup: {
let: {"a": "$ma", "b": "$mb"},
pipeline: [
{$match: {
$expr: {$and: [{$eq: ["$la", "$$a"]}, {$eq: ["$lb", "$$b"]}]}
}},
{$project: { la: 1, lb: 1, _id: 0}}
],
from: "MyOtherColl",
as: "subs"
}}
])
and index
db.MyOtherColl.createIndex({“la”: 1, “lb”: 1})
inner query is not covered according to docsExamined
.
If I explain()
inner query itself, it seems that $expr
breaks this: .aggregate([{$match: {la: "va", lb: "vb", _id: 0}}, {$project:...}])
will be covered, while equivalent with $expr
(.aggregate([{$match: {$expr: ...}}, {$project:...}])
will be not.
Is this a limitation of covered queries or am I missing something?