Are MongoDB $facet sub-pipelines asynchronous and executed in parallel?

I am eager to know whether MongoDB’s Aggregation Framework processes each sub-pipeline inside $facet in parallel.

It is specified in the doc that:

Each sub-pipeline within $facet is passed the exact same set of input documents. These sub-pipelines are completely independent of one another.

Does that mean each sub-pipeline in $facet is send to a separate thread and processed asynchronously?

1 Like

No, all aggregation pipelines are executed sequentially, including $facet.

If you’re prepared to add some complexity and overhead to your client code, there’s a blog post exploring using custom code to execute facet sub-pipelines in parallel and then manually merging the results:

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.