Migration guide · MongoDB

MongoDB to OpenSearch: offload search and analytics, or replace?

Most teams that connect MongoDB to OpenSearch keep MongoDB for writes and add OpenSearch for search and analytics. Here are the sync options and the one case where replacing makes sense.

45 minutes with an engineer: we review your workload and sketch the design.

  • Change streams
  • Search offload
  • OpenSearch
What are the steps to set it up?

The usual pattern is to keep MongoDB as the source of truth and copy documents into OpenSearch for search and analytics. Sync with a change-stream consumer that writes through OpenSearch's bulk API, with Debezium, or with periodic reindexing. Replace MongoDB with OpenSearch only for data you can rebuild, such as logs and events (checked 5 Dec 2026).

Customers

  • Microsoft logo
  • Henry Schein logo
  • Enbridge logo
  • Gojek logo

Partners

  • Broadcom logo
  • Redis logo
  • VMware Tanzu logo
  • OSSeva logo

Should MongoDB stay the source of truth or be replaced?

Keep MongoDB as the source of truth in nearly every case. OpenSearch is built to search and aggregate documents quickly, not to be the only copy of business data. Replace MongoDB only for collections that are append-only, such as logs, events and metrics, where the data can be re-created or its loss is tolerable.

PatternHow it worksPick it whenWatch for
Offload (recommended)Writes go to MongoDB; a sync copies changes into OpenSearch; search and dashboards read OpenSearchSearch relevance, filtering or analytics is slowing MongoDB or cannot be built on itSync lag, mapping drift and a second system to run
Replace for event dataProducers write straight to OpenSearch; MongoDB stops holding that collectionThe data is time-series or log-like and never updatedNo other store holds the data unless you add one
Stay inside MongoDBUse MongoDB's own searchText search is modest and you do not want a second engineSelf-managed deployments run the search process themselves

Pattern guidance is ours; the MongoDB Search deployment model is cited below.

Do not skip the third row. MongoDB's own documentation says Atlas manages its search process for you, while on Community Edition or another self-managed deployment you install, configure and operate it yourself (MongoDB Search deployment options, checked 5 Dec 2026). If your search need is simple, that may be less work than a sync pipeline. OpenSearch earns its place when you need its query language, analytics, dashboards or a search tier you can scale independently.

How do you sync MongoDB to OpenSearch?

There are four documented routes: your own change-stream consumer writing through the bulk API, Debezium with an OpenSearch sink, a scheduled batch export and reindex, and, if you run Amazon DocumentDB instead of MongoDB, OpenSearch Data Prepper's DocumentDB source. Pick by how fresh the index must be and how much you want to run.

RouteFreshnessWhat you runSource
Change-stream consumer plus _bulkSecondsA small service you write and ownMongoDB, OpenSearch
Debezium MongoDB connector plus an OpenSearch sink connectorSecondsKafka Connect, the connectors and their offsetsDebezium, Aiven sink
Scheduled export and bulk reindexMinutes to hoursA job; no streaming infrastructuremongoexport, OpenSearch
Data Prepper documentdb sourceSecondsData Prepper plus an S3 bucketData Prepper

Sources linked in each row; checked 5 Dec 2026. The Data Prepper source is documented for Amazon DocumentDB only. We found no MongoDB source in its list of sources.

The change-stream route is the lightest. MongoDB change streams work on replica sets and sharded clusters, report events only after they persist to a majority of members, and can be resumed from a token as long as the oplog still holds that point (change streams docs, checked 5 Dec 2026). A consumer reads events, batches them and sends them through the NDJSON-based Bulk API, which OpenSearch documents as reducing round trips and speeding up indexing (bulk API docs, checked 5 Dec 2026).

The Debezium route trades code for infrastructure. Its MongoDB connector is documented for the same topologies, takes an initial snapshot and emits create, update, delete and read events. It runs in Kafka Connect, as does Aiven's open-source OpenSearch sink, so you take on that platform (Debezium docs; Aiven connector README, checked 5 Dec 2026). If you already run Kafka Connect, it is the lowest-effort option. If you do not, a small consumer is usually simpler.

45 minutes with an engineer: we review your workload and sketch the design, then price it.

What goes wrong when you sync MongoDB into OpenSearch?

Deletes, partial updates, mappings and reindexing cause most of the trouble. Plan how a deleted document is removed, whether updates carry the full document, how fields are typed in OpenSearch, and how you rebuild the index from scratch without downtime.

Updates that carry only changes.
By default a change stream returns only the changed fields. The fullDocument updateLookup option fetches the current document, but that can be missing if the document was deleted first, and the docs warn it can cause "Resume Token Not Found" errors under load with a $match filter. Pre- and post-images (MongoDB 6.0 and later) are the recommended alternative (change streams docs, checked 5 Dec 2026).
Deletes.
Handle the delete event explicitly, using the document id to delete from OpenSearch. In Debezium, a delete is operation code d followed by a tombstone record (Debezium docs, checked 5 Dec 2026).
Idempotency.
Use the MongoDB _id as the OpenSearch document id. Replaying an event then overwrites the same document instead of creating a duplicate.
Mappings.
MongoDB is schema-flexible and OpenSearch indexes are not forgiving about field type changes. Define mappings up front for the fields you search, and decide how ObjectId, dates and decimals are typed.
Nested arrays.
Arrays of objects behave differently when searched. Test the queries you care about against the index mapping, not just the ingest.
Resume gaps.
If the consumer is down longer than the oplog retention, the resume token is lost and you need a full reindex. Alert on consumer lag.
Reindexing.
Keep a way to rebuild: write to a new index, load it from a fresh snapshot while changes buffer, then repoint the application. Test this before you need it.

What are the steps to set it up?

Define what must be searchable, design the OpenSearch mappings, open the change stream, load the existing data, apply the stream, then point search and dashboards at OpenSearch. MongoDB's writes never stop, so there is no application cutover for the write path.

  1. Scope

    List the collections and fields that need search or analytics, and the freshness each query needs.

  2. Map

    Create the OpenSearch indexes with explicit mappings. Keep the MongoDB _id as the document id.

  3. Open the stream

    Start the change stream and record its resume token before reading any existing data.

  4. Backfill

    Export the existing documents and bulk-load them in batches. Throttle so MongoDB's primary is not starved.

  5. Apply

    Process the stream from the recorded token, batching events into bulk requests, with retries and a dead-letter store for rejected documents.

  6. Switch reads

    Move search and dashboard queries to OpenSearch, compare results against MongoDB for a sample, and watch lag.

If you are moving an existing Elasticsearch deployment rather than adding search to MongoDB, that is a different job; see Elasticsearch to OpenSearch and OpenSearch vs Elasticsearch.

Who runs OpenSearch, and where?

OpenSearch is open source, so the engine can run in more places than one vendor's service. OSStend runs community open-source OpenSearch and MongoDB for customers, 24/7 with named engineers, in OSStend's cloud, your cloud account, your data center, on Kubernetes or OpenShift, or air-gapped.

Managed OpenSearch covers the search side, and managed MongoDB covers the source database, so the sync between them can be designed as one system and the failover rehearsed before go-live. Pricing is quoted per design on the pricing page. If your MongoDB is on Atlas and the bill is the driver, see also moving off Atlas.

When does MongoDB to OpenSearch fit, and when does it not?

It fits when search quality, filtering across many fields or analytics on documents has outgrown what MongoDB serves comfortably. It does not fit when a simple text index would do, or when the team cannot run a second system and its sync.

Contact us if

  • You need relevance ranking, faceting or log-style analytics over large document sets.
  • You want the search tier to scale and fail independently of the database that takes writes.
  • Index freshness of seconds to minutes is acceptable.
Talk to an engineer

Not a fit if

  • MongoDB's built-in search already covers the need and you would rather not run two engines.
  • Every read must reflect the latest write with no lag; a search index is eventually consistent with its source.
  • You plan to make OpenSearch the only copy of data that cannot be rebuilt.

Questions about MongoDB to OpenSearch

How do I migrate MongoDB to OpenSearch?

Treat it as a sync, not a one-time move: open a change stream, backfill existing documents through the bulk API, then apply the stream to keep the index current. MongoDB stays the source of truth (change streams docs, checked 5 Dec 2026).

Can OpenSearch replace MongoDB?

For append-only data such as logs and events, yes. For transactional business data, we advise against making a search engine the only copy.

Does OpenSearch Data Prepper have a MongoDB source?

Its documented source is for Amazon DocumentDB, using an export plus change streams through an S3 bucket (Data Prepper docs, checked 5 Dec 2026). We found no MongoDB source in its list.

Does MongoDB Atlas support change streams for syncing?

Change streams are available on replica sets and sharded clusters (MongoDB docs, checked 5 Dec 2026), which is what an Atlas cluster is. Check your tier's oplog and connection limits.

Is MongoDB's built-in search an alternative to OpenSearch?

For modest needs, possibly. Atlas manages the search process; on self-managed MongoDB you run it yourself (MongoDB docs, checked 5 Dec 2026).

Talk to an engineer

Plan your MongoDB and OpenSearch design with an engineer

45 minutes with an engineer: the current setup is reviewed, the method is chosen and the cutover is sketched. Designs are written and signed off first, and a failover is rehearsed before go-live. Pricing is quoted per design.

  • A design sketch for your workload, not a plan menu
  • A zero-downtime cutover path for what you run today
  • A price for that design, after the review
See pricing →

Your request goes to Scott Sternloff, Senior Enterprise Architect. No newsletter sign-up.

Get a quoteTalk to an engineer
2Engines Optional
3Where should it run?
4What do you need?

Your request goes to Scott Sternloff, Senior Enterprise Architect. No newsletter sign-up.