Facets and counts text search
In Chapter 9, Trend Analysis Examples, you learned about using a core MongoDB aggregation framework stage ($facet
) to classify the data in a collection by different dimensions. However, as that chapter highlighted, the aggregation has no choice but to perform a full-collection scan to identify and assemble the faceted results. With Atlas, you can employ an alternative mechanism to generate faceted results faster, which you should prefer whenever Atlas is an option. This example will walk you through how to use Atlas Search to create facets for a collection.
Note
For this example, you require MongoDB version 4.4 or above. This is because you'll be using the facet
option in the $searchMeta
stage introduced in version 4.4.
Scenario
You help run a bank's call center and want to analyze the summary descriptions of customer telephone inquiries recorded by call center staff. You want to look for customer calls that mention fraud and understand...