0

In my aggregation query there is a static $lookup stage. Static in the sense that very document will have the same result from the $lookup. Hence, MongoDB will performance one lookup and cache the results. I further know that the result from this $lookup will be a an array of 1000 subdocuments. Thus, it is a large array. I also know that this array is for reading only and will never be modified. And so there is no reason to copy this array for each document. Each document can simply have this array's reference.

Is it possible to specify to MongoDB exactly this, for the sake of performance?

  • Not as far as I know. But maybe you could achieve something similar by taking a different approach? It's hard to say based on the limited description so far, but maybe something like `$unionWith` could help. All depends on how you are using/processing this information – user20042973 Jun 06 '23 at 14:38

0 Answers0