A partial index indexes only documents that satisfy a specified filter expression. By indexing a subset of a collection, it reduces storage requirements and the cost of index creation and maintenance. section 7.4.1
Create a partial index with these practical steps:
- Choose the indexed fields and the subset of documents that should receive index entries. section 7.4.1
- Call db.collection.createIndex() and provide the condition through partialFilterExpression. section 7.4.1
- Use supported filter operators such as equality, $exists, comparison operators, $type, $and, $or, and $in. section 7.4.1
Index movie documents
A compound index on year, type, and imdb.rating can be restricted to documents whose type equals "movie". This keeps non-movie documents out of the index while preserving the selected fields for indexed movie documents. section 7.4.1
db.getSiblingDB('sample_mflix').movies.createIndex(
{
year: 1,
type: 1,
"imdb.rating": 1
},
{
partialFilterExpression: { type: { $eq: "movie" } }
} // Creates a partial index on the movies collection
➥for documents where type is "movie"
)
Run the mongosh command to create the filtered compound index on sample_mflix.movies. section 7.4.1

