-
Type: Task
-
Resolution: Duplicate
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Server
-
Labels:None
When reading the docs for `$lookup`, I see that `as` says that the result shall be put in a document as an array. This immediately makes me think of the 16M BSON document size limitation and search the `$lookup` page for some note/discussion about the BSON document size limitation. I couldn’t figure out how `$lookup` would ever be useful if it always output the results into an array because for many large datasets it would be impossible to stay under the BSON document size limit.
Then I found https://stackoverflow.com/a/45726501/429091 which in the second paragraph states:
> The counter for this is to process with an `$unwind` which immediately follows the $lookup pipeline stage. This actually alters the behavior of `$lookup` in such that instead of producing an array in the parent, the results are instead a "copy" of each parent for every document matched.
Suddenly things made sense.
I think that this is a natural topic to be discussed/mentioned in the `$lookup` documentation. In fact, I think the `$lookup` documentation should *recommend* adding an `$unwind` stage immediately after to reduce the chance of hitting the document limit.
- is related to
-
DOCS-10791 Comment on: "manual/reference/operator/aggregation/lookup"
- Closed