Scale Performance with View Support for MongoDB Atlas Search and Vector Search

Amy Jian and Miranda Barrigas

We are thrilled to announce the general availability (GA) of View Support for MongoDB Atlas Search and Atlas Vector Search, available on MongoDB versions 8.0+. This new feature allows you to perform powerful pre-indexing optimizations—including Partial Indexing to filter your collections, and Document Transformation to reshape your data for peak performance.

View Support for MongoDB Atlas Search helps you build more efficient, performant, and cost-effective search experiences by giving you precise control over your search strategy. Let's look at how it works.

How it works in 3 simple steps

At its core, View Support is powered by MongoDB views, queryable objects whose contents are defined by an aggregation pipeline on other collections or views.

Getting started is straightforward:

  1. Create a view: Define a standard view using an aggregation pipeline to filter or transform your source collection. This feature is designed to support views that contain the stages $match with an $expr operator, $addFields, and $set.

    Note: Views with multi-collection stages like $lookup are not supported for search indexing at this time.

  2. Index the view: Build your MongoDB Atlas Search or Atlas Vector Search index directly on the view you just created.

  3. Query the view: This is the best part. You run your $search, $searchMeta, or $vectorSearch queries directly against the view itself to get results from your perfectly curated data.

With this simple workflow, you can now fine-tune exactly what and how your data is indexed. The two key capabilities you can use today are Partial Indexing and Document Transformation.

Figure 1. High-level architectural diagram of search index replication on a view.
This diagram is titled Search Index on a View. On the left of the diagram is a large box labeled disk storage, which contains collection and search index, an arrow goes between the two labeled initial sync plus changestream. Next to the arrow is another box labeled view pipeline.
Search indexes perform initial sync on the collection and apply the view pipeline before saving the search index to disk storage.

Index only what you need with partial indexing

Often, only a subset of your data is truly relevant for search. Imagine an e-commerce catalog where only "in-stock" products should be searchable or a RAG system where only documents containing vector embeddings will be retrieved.

With Partial Indexing, you can use a $match stage in your view to create a highly-focused index that:

  • Reduces index size: Dramatically shrink the footprint of your search indexes, leading to cost savings and faster operations.

  • Improves performance: Smaller indexes mean faster queries and index build times.

Optimize your data model with document transformation

Beyond filtering, you can also reshape documents for optimal search performance. Using $addFields or $set in your view, you can create a search-optimized version of your data without altering your original collection.

This is perfect for:

  • Pre-computing values: Combine a firstName and lastName into a fullName field for easier searching, or pre-calculate the number of items in an array.

  • Supporting all data types: Convert incompatible data types, like Decimal128, into search-compatible types like Double. You can also convert booleans or ObjectIDs to strings to enable faceting.

  • Flattening your schema: Promote important fields from deeply nested documents to the top level, simplifying queries and improving performance over expensive $elemMatch operations.

  • Testing different vector dimensionalities: Splice large MRL Embeddings from Voyage into smaller ones to evaluate the tradeoffs between accuracy and performance.

For example, consider a vacation home rental company with a listings collection storing reviews as an array of objects. To enable end-users to filter for listings with > N reviews, they create a view called listingsSearchView. The view pipeline of listingsSearchView uses an $addFields stage to add the numReviews field, which is computed based on the size of the reviews array.

By creating a search index on listingsSearchView, they can run efficient $search queries on numReviews without compromising data integrity in the source collection.

Figure 2. High-level architectural diagram of running search queries on a view.
This diagram starts on the left with a image representing search queries from client. From here, the path goes to view and then to a box titled disk storage which contains search index. Next, the data goes to mongod, and then through idLookup it goes to collection documents. Then, via the view pipeline the client is able to view documents.
After the search index identifies documents to return, mongod applies the view pipeline to return the view documents.

Why these optimizations are critical for scaling

As your application and data volume grow, search efficiency can become a bottleneck. View Support for MongoDB Atlas Search provides the critical tools you need to maintain blazing-fast performance and control costs at scale by giving you granular control over your indexes.

We are incredibly excited to see how you use these new capabilities to build the next generation of powerful search experiences on MongoDB Atlas.

Ready to get started? Dive into the documentation to learn more: Atlas Search, Atlas Vector Search.

Note: We plan to add compatibility for more types of Views in the future. If there’s a stage that you want to see, please let us know.