Skip to main content

SHARDING_FILTER

Short Description

Filtering out orphan documents from shards

Detailed Description​

In a MongoDB explain plan, SHARDING_FILTER is an execution stage you’ll see in a sharded cluster.

In simple terms:

  • The SHARDING_FILTER stage removes documents that don’t belong to the current shard, according to the collection’s shard key range.
  • This is important because, in a sharded setup, a query might return documents that technically belong to another shard (“orphan” documents, often because of chunk migrations or rebalancing).

Why does MongoDB do this?

  • To make sure that only the correct documents for the current shard’s range are included in the query results.
  • It helps maintain accurate and consistent query results across all your shards.

Summary:

SHARDING_FILTER is a MongoDB execution stage that filters out documents not owned by the shard currently processing the query. You’ll only see it in sharded clusters. In MongoDB Compass, if you see this stage, it means your deployment is sharded and MongoDB is making sure each shard returns only its rightful data.

Search online​

If this article doesn't have the information you need you can try searching online. Remember, you can contribute suggestions to this page.