The Atlas Search facet operator groups matching search results by values or ranges in specified fields and returns a count for each group. It is a search collector for producing metadata, rather than an operator that finds matches. Faceted counts can help users navigate a large result set by inspection outcome, sector, or other categories. section 11.5 section 11.5.1
Facet fields support dateFacet, numberFacet, and stringFacet types. Choose fields whose groups will help people refine results: a status field gives named categories, while a numeric field can supply ranges. section 11.5 section 11.5.1
Count categories after a business-name search
Search inspection records for business names matching “HOT DOG,” allowing a minor spelling error. The illustrated pipeline then uses the aggregation stage $facet to count matches separately by inspection result, inspection year, and sector. Its output includes 74 matches from 2015 and 8 from 2016. This demonstrates the value of faceted results, but $facet is an aggregation stage—not the Atlas Search facet collector. section 11.5.1 section 11.5
When adapting the example, distinguish the two APIs: use the Atlas Search facet collector for search-result metadata, or place an aggregation $facet stage after $search to run separate counting pipelines over matches. The illustrated $facet pipeline is not a copyable syntax example for the search collector. section 11.5 section 11.5.1
