This article is out of date. Check out this new post for the most up-to-date way to MongoDB Atlas Search to find your favorite movies. 📽 🎞
Giving your users the ability to find exactly what they are looking for in your application is critical for a fantastic user experience. With the new MongoDB Atlas Full-Text Search service, we have made it easier than ever to integrate simple yet sophisticated search capabilities into your MongoDB applications. To demonstrate just how easy it is, let's build a movie search engine - in only 10 minutes.
Built on Apache Lucene, Full-Text Search adds document data to a full-text search index to make that data searchable in a highly performant, scalable manner. This tutorial will guide you through how to build a web application to search for movies based on a topic using Atlas' sample movie data collection on a free tier cluster. We will create a Full-Text Search index on that sample data. Then we will query on this index to filter, rank and sort through those movies to quickly surface movies by topic.

Armed with a basic knowledge of HTML and Javascript, here are the tasks we will accomplish:
- ☐ Spin up an Atlas cluster and load sample movie data
- ☐ Create a Full-Text Search index in movie data collection
- ☐ Write an aggregation pipeline with $searchBeta operator
- ☐ Create a RESTful API to access data
- ☐ Call from the front end
Now break out the popcorn, and get ready to find that movie that has been sitting on the tip of your tongue for weeks.

To Get Started, we will need:
A free tier (M0) cluster on MongoDB Atlas. Click here to sign up for an account and deploy your free cluster on your preferred cloud provider and region.
SPECIAL OFFER: Want to try our Full-Text Search on a cluster of your own?
YouOldMaid100
for $100 of Atlas credit. For information on redeeming Atlas credit, see Atlas Billing.The Atlas sample dataset loaded into your cluster. You can load the sample dataset by clicking the ellipse button and Load Sample Dataset.
For more detailed information on how to spin up a cluster, configure your IP address, create a user, and load sample data, check out Getting Started with MongoDB Atlas from our documentation.
- (Optional) MongoDB Compass. This is the free GUI for MongoDB that allows you to make smarter decisions about document structure, querying, indexing, document validation, and more. The latest version can be found here https://www.mongodb.com/download-center/compass.
Once your sample dataset is loaded into your database, let's have a
closer look to see what we are working within the Atlas Data Explorer.
In your Atlas UI, click on Collections to examine the movies
collection in the new sample_mflix
database. This collection has
over 23k movie documents with information such as title, plot, and cast.

- ☒ Spin up an Atlas cluster and load sample movie data
- ☐ Create a Full-Text Search index in movie data collection
- ☐ Write an aggregation pipeline with $searchBeta operator
- ☐ Create a RESTful API to access data
- ☐ Call from the front end
#Create a Full-Text Search Index
Our movie search engine is going to look for movies based on a topic. We will use Full-Text Search to query for specific words and phrases in the 'fullplot' field.
The first thing we need is a Full-Text Search index. Click on the tab titled SearchBETA under Collections. Clicking on the green Create a Search Index button will open a dialog that looks like this:

By default, we dynamically map all the text fields in your collection. This suits MongoDB's flexible data model perfectly. As you add new data to your collection and your schema evolves, dynamic mapping accommodates those changes in your schema and adds that new data to the Full-Text Search index automatically.
Let's accept the default settings and click Create Index. And that's all you need to do to start taking advantage of Lucene in your MongoDB Atlas data!
- ☒ Spin up an Atlas cluster and load sample movie data
- ☒ Create a Full-Text Search index in movie data collection
- ☐ Write an aggregation pipeline with $searchBeta operator
- ☐ Create a RESTful API to access data
- ☐ Call from the front end
#Write Aggregation Pipeline With $searchbeta Operator
Full-Text Search queries take the form of an aggregation pipeline stage. The $searchBeta stage performs a search query on the specified field(s) covered by the Full-Text Search index and must be used as the first stage in the aggregation pipeline.
Let's use MongoDB Compass to see an aggregation pipeline that makes use of this Full-Text Search index. For instructions on how to connect your Atlas cluster to MongoDB Compass, click here.
You do not have to use Compass for this stage, but I really love the easy-to-use UI Compass has to offer. Plus the ability to preview the results by stage makes troubleshooting a snap! For more on Compass' Aggregation Pipeline Builder, check out this