1

Suppose that after $match stage, 10,000 documents will be passed into a $lookup stage. For each of those 10,000 documents, the $lookup will need to join based on its _id. The foreign field to join by will be indexed and almost unique - as it is made up of _id.

Will each $lookup for each of the 10,000 documents have O(1) due to the index?

So is it safe to assume that this pipeline will be fast and scalable?

  • Never assume, test and verify. – Joe Jan 26 '23 at 07:12
  • @Joe But this question seems to be answerable based upon raw first principles, no? – Bear Bile Farming is Torture Jan 27 '23 at 16:51
  • 2
    If all that matters is big O, sure, but at some point the amount of memory, disk bandwidth, connection counts, etc. have a bigger impact on scalability. So big O is a great tool for getting started, but it would be foolhardy to say that it is safe to assume scalability based solely on big O. – Joe Jan 27 '23 at 21:02

0 Answers0