Atlas Search: Facet
🚀 Goal: Faceted Search That Shines
Your platform’s search is already fast and smart, but now your business wants to empower users to explore and filter results with ease. Imagine a guest searching for “hawaii” and instantly narrowing down results by amenities, property type, or number of beds—all with a single click. As the backend engineer, you’re about to make this next-level discovery experience a reality with MongoDB Atlas Search facets.
Faceted search lets your users slice and dice results, making it effortless to find exactly what they want—turning every search into a personalized journey.
đź§© Exercise: Facets in Action
-
Open the File
Navigate toserver/src/lab/
and opensearch-2.lab.js
. -
Locate the Function
Find thefacetSearch
function in the file. -
Shape the Pipeline
- Use
$searchMeta
on thedefault
index. - Apply
facet
in your pipeline. - For the
operator
, reuse theautocomplete
search from the previous exercise. - Create these facets:
amenities
: a string facetproperty_type
: a string facetbeds
: a numeric facet with boundaries from 0 to 9, and “Other” for any additional values
- Use
🚦 Test Your API
- Go to
server/src/lab/rest-lab
. - Open
search-2-lab.http
. - Click Send Request to call the API.
- Make sure you see valid results in the response.
🖥️ Frontend Validation
Type "hawaii"
in the search bar and watch the new facets appear—instantly filter and explore your results!
With this step, you’re not just adding filters—you’re giving your users the power to discover their perfect stay, their way.
Ready to make search truly interactive? Let’s get started!