0

assume I have collection A like:

A{
  b: bid
}

and collection B with index on field x

assume I do an aggregation on A like:

{ $lookup from B as b where b._id = a.bid}
{ $match b.x = something}

will the index on B improve query?

Mars
  • 873
  • 1
  • 11
  • 24
  • Not like that since it's matching on an array within the document and not the collection. Put an `$unwind` directly after the `$lookup` and before the `$match` and it actually will. Look at the "explain" output to see why. – Neil Lunn May 09 '18 at 05:29
  • See [Aggregate $lookup Total size of documents in matching pipeline exceeds maximum document size](https://stackoverflow.com/a/45726501/2313887) – Neil Lunn May 09 '18 at 05:31
  • https://de.slideshare.net/mongodb/doing-joins-in-mongodb-best-practices-for-using-lookup - in particular slide 16 – dnickless May 09 '18 at 05:38

0 Answers0