docs/reference/online-stores/mongodb.md
The MongoDB online store provides support for materializing feature values into MongoDB for serving online features.
AsyncMongoClient (no Motor dependency required)In order to use this online store, you'll need to install the MongoDB extra (along with the dependency needed for the offline store of choice):
pip install 'feast[mongodb]'
You can get started by using any of the other templates (e.g. feast init -t gcp or feast init -t snowflake or feast init -t aws), and then swapping in MongoDB as the online store as seen below in the examples.
{% code title="feature_store.yaml" %}
project: my_feature_repo
registry: data/registry.db
provider: local
online_store:
type: mongodb
connection_string: "mongodb+srv://username:[email protected]/" # pragma: allowlist secret
database_name: feast_online_store
{% endcode %}
{% code title="feature_store.yaml" %}
project: my_feature_repo
registry: data/registry.db
provider: local
online_store:
type: mongodb
connection_string: "mongodb://username:password@localhost:27017/" # pragma: allowlist secret
database_name: feast_online_store
collection_suffix: features
{% endcode %}
{% code title="feature_store.yaml" %}
project: my_feature_repo
registry: data/registry.db
provider: local
online_store:
type: mongodb
connection_string: "mongodb://host1:27017,host2:27017,host3:27017/?replicaSet=myReplicaSet"
database_name: feast_online_store
client_kwargs:
retryWrites: true
w: majority
{% endcode %}
{% code title="feature_store.yaml" %}
project: my_feature_repo
registry: data/registry.db
provider: local
online_store:
type: mongodb
connection_string: "mongodb+srv://cluster.mongodb.net/"
database_name: feast_online_store
collection_suffix: features
client_kwargs:
maxPoolSize: 50
minPoolSize: 10
serverSelectionTimeoutMS: 5000
connectTimeoutMS: 10000
{% endcode %}
The full set of configuration options is available in MongoDBOnlineStoreConfig.
The MongoDB online store uses a single collection per project with entity key collocation. Features from multiple feature views for the same entity are stored together in a single document.
The example shows a single entity. It contains 3 features from 2 feature views: "rating" and "trips_last7d" from Feature View "driver_stats", and "surge_multiplier" from "pricing" view. Each feature view has its own event timestamp. The "created_timestamp" marks when the entity was materialized.
{
"_id": "<serialized_entity_key>", // Binary entity key (bytes)
"features": {
"driver_stats": {
"rating": 4.91,
"trips_last_7d": 132
},
"pricing": {
"surge_multiplier": 1.2
}
},
"event_timestamps": {
"driver_stats": ISODate("2026-01-20T12:00:00Z"),
"pricing": ISODate("2026-01-21T08:30:00Z")
},
"created_timestamp": ISODate("2026-01-21T12:00:05Z")
}
_id field: Uses the serialized entity key (bytes) as the primary key for efficient lookupsThe online store automatically creates the following index:
_id (automatic in MongoDB), set to the serialized entity key.No additional indexes are required for the online store operations.
The MongoDB online store provides native async support using PyMongo 4.13+'s stable AsyncMongoClient. This enables:
Both sync and async methods are fully supported:
online_read / online_read_asynconline_write_batch / online_write_batch_asyncThe set of functionality supported by online stores is described in detail here. Below is a matrix indicating which functionality is supported by the MongoDB online store.
| MongoDB | |
|---|---|
| write feature values to the online store | yes |
| read feature values from the online store | yes |
| update infrastructure (e.g. tables) in the online store | yes |
| teardown infrastructure (e.g. tables) in the online store | yes |
| generate a plan of infrastructure changes | no |
| support for on-demand transforms | yes |
| readable by Python SDK | yes |
| readable by Java | no |
| readable by Go | no |
| support for entityless feature views | yes |
| support for concurrent writing to the same key | yes |
| support for ttl (time to live) at retrieval | no |
| support for deleting expired data | no |
| collocated by feature view | no |
| collocated by feature service | no |
| collocated by entity key | yes |
To compare this set of functionality against other online stores, please see the full functionality matrix.