<@U04S8PLJWMT> I'm using connector MongoDb v 2.0.2...
# ask-ai
i
@kapa.ai I'm using connector MongoDb v 2.0.2 to stync data from one Mongodb to another. I am doing incremental syncs on the collections from the db. At the first sync it synced all existing data, but afterwards no new data was synced. The syncs show 0 records loaded, no error logs. What could be the issue
k
Based on the information in the knowledge sources, there are a few common reasons why incremental syncs with the MongoDB v2 connector might not load new data after the initial sync, even though no errors are shown: 1. Cursor Field Configuration: If you are using a custom cursor field (e.g., a date field like
date_scrap
), ensure that: - The field exists in all documents. - The field's data type is consistent across all documents. - New records have a value for this field that is greater than the last synced value. If the field is not updated or is missing in new documents, Airbyte will not detect them as new for incremental syncs. This is a common issue, as described in a similar forum post where no new records were synced after the first run due to cursor field configuration issues. Review your cursor field setup and the data in your source collection to ensure it matches expectations [Forum Post: Mongodb incremental + append - no row after first sync](https://discuss.airbyte.io/t/1641). 2. Connector Limitations: The MongoDB v2 connector has some limitations: - Collections with different data types for the
_id
field among documents are not supported. - Empty collections are excluded from schema discovery. - If you are using incremental syncs, ensure that the oplog retention is sufficient and that the sync frequency is appropriate, but since you are not seeing errors, this is less likely to be the cause in your case [Connector Limitations](https://docs.airbyte.com/integrations/sources/mongodb-v2/mongodb-v2-troubleshooting#connector-limitations). 3. No New Data Matching the Cursor: If no new records have a cursor value greater than the last synced value, Airbyte will not sync any new records. Double-check that new documents are being inserted with the correct cursor field values. 4. Schema Discovery Issues: If the schema changes (e.g., new fields are added or removed), and schema enforcement is enabled, it could potentially cause issues with detecting new records, though this usually results in errors. What to check: - Verify the cursor field is present and correctly populated in all new documents. - Confirm that new documents have a cursor value greater than the last synced value. - Check the Airbyte connection settings for the correct cursor field and sync mode. - Review the connector and Airbyte logs for any warnings or info messages that might indicate skipped records or schema issues. If after these checks the issue persists and no errors are logged, you may want to review the Airbyte logs at a more detailed level or try a full refresh sync to see if new records are picked up. If you need more specific troubleshooting, please provide details about your cursor field configuration and examples of new documents that are not being synced.
i
the cursor field is _ab_cdc_cursor.
@kapa.ai the cursor field is _ab_cdc_cursor. , wha telse do you need ?
k
A message from kapa.ai
Thank you for clarifying that your cursor field is
_ab_cdc_cursor
. Based on the knowledge sources, here are the key points to consider: - Incremental syncs rely on the cursor field: Airbyte will only sync records where the value of the cursor field is greater than (or, depending on mode, greater than or equal to) the last synced value. If new records do not have a
_ab_cdc_cursor
value greater than the last synced value, they will not be picked up in subsequent syncs. This is a common cause for seeing "0 records loaded" after the initial sync, even if new data exists in the source collection. This behavior is described in the documentation for incremental syncs and their known limitations [Incremental Sync - Append: Known Limitations](https://docs.airbyte.com/platform/using-airbyte/core-concepts/sync-modes/incremental-append#known-limitations). - CDC and oplog retention: If you are using Change Data Capture (CDC) mode, the connector relies on MongoDB's oplog. If the oplog does not retain changes long enough between syncs, or if the saved offset becomes invalid, you may encounter issues. However, in your case, since there are no error logs, this is less likely the cause, but it's still important to ensure your oplog retention is sufficient for your sync frequency [MongoDB CDC Troubleshooting](https://github.com/airbytehq/airbyte/issues/48496). - No errors, but no new data: If there are no errors and no new records are synced, it strongly suggests that either: - No new records have a
_ab_cdc_cursor
value greater than the last synced value. - The connector is not detecting new changes due to how the cursor is being managed or populated. What else is needed to diagnose further: - Are new records being inserted into the source collection with a valid and increasing
_ab_cdc_cursor
value? - Is the
_ab_cdc_cursor
field being set automatically by the connector, or are you populating it yourself? - Can you provide an example of a new document (with the
_ab_cdc_cursor
field) that is not being synced? If the
_ab_cdc_cursor
is managed by Airbyte and you are using CDC, you should not need to set it manually. If you are setting it yourself, ensure its value is always increasing for new records. If you can share a sample of a new document and confirm how the
_ab_cdc_cursor
is being set, it would help narrow down the issue. Otherwise, based on the knowledge sources, the most likely cause is that the new records do not have a cursor value greater than the last synced value, so they are not being picked up in incremental syncs.
i
@kapa.ai but where is this curso stored? they aren'n in the documents of course, it isn't a field for the source documents
k
A message from kapa.ai
The cursor value (such as
_ab_cdc_cursor
) used for incremental syncs in Airbyte is not stored in your source documents. Instead, Airbyte maintains the cursor state internally. Specifically, Airbyte persists this state—including the most recent cursor value—in its own internal Postgres database. This allows Airbyte to keep track of which records have already been synced, even if the worker or pod is restarted. You can view this state by connecting to the Airbyte Postgres database and querying the
state
table. For example:
Copy code
sql SELECT * FROM state;
This table contains the cursor values and other state information for each connection. The cursor is used by Airbyte to determine which records to sync next, but it is not written back to your source data in MongoDB. This mechanism is described in the Airbyte documentation and tutorials: > Airbyte persists this state ([StatePersistence.java](https://github.com/airbytehq/)) to an internal Postgres database. > The contents of the state database can be viewed with the following command: >
SELECT * FROM state;
> [Explore Airbyte’s incremental data synchronization](https://airbyte.com/tutorials/incremental-data-synchronization#step-2) So, the cursor is managed and stored by Airbyte itself, not in your MongoDB documents.
i
@kapa.ai could It be the resume token ? I mean what can go wrong here>
k
A message from kapa.ai
Yes, the issue could be related to the resume token, especially since you are using the MongoDB v2 connector with incremental syncs (CDC mode). Several users have reported that problems with the resume token can cause incremental syncs to stop picking up new records, even when no errors are shown. What can go wrong with the resume token? 1. Resume Token Not Updating: There are known issues where the resume token (which tracks the last processed position in the MongoDB oplog/change stream) does not update correctly in the Airbyte state. This can happen even if new data is present, resulting in subsequent syncs not processing new records. This has been reported in multiple issues, where the state contains an outdated resume token that never advances, causing the connector to miss new changes [mongo states saveState server_id is normalized](https://github.com/airbytehq/airbyte/issues/64108), [Failed syncs due to [config_error] Saved offset is not valid](https://github.com/airbytehq/airbyte/issues/62833). 2. Resume Token Only Updates When New Records Exist: By default, the connector may only update the resume token when new records are found. If your collections are rarely updated, the resume token can become stale, and the connector will have to scan through a large number of irrelevant oplog entries, which can eventually lead to timeouts or missed data. This behavior is described as a critical operational issue in the connector [Update resume token to latest oplog position even when no new records exist](https://github.com/airbytehq/airbyte/issues/48435). 3. State Key Issues: There are cases where the state is saved under multiple keys (e.g., one for the MongoDB URL and one for a normalized server_id), and only one of them is updated. If the connector reads from the stale key, it will not pick up new changes, even though another key may have the correct, updated resume token [Failed syncs due to [config_error] Saved offset is not valid](https://github.com/airbytehq/airbyte/issues/62833). 4. Oplog Retention and Resume Token Validity: If the resume token points to an oplog entry that has been purged (because the oplog retention window was exceeded), the connector will fail to resume and may require a full refresh. However, this usually results in an error, not just 0 records synced [Connector Limitations](https://docs.airbyte.com/integrations/sources/mongodb-v2/mongodb-v2-troubleshooting#connector-limitations). Summary: If your incremental syncs are not picking up new data and there are no errors, it is very likely that the resume token in the Airbyte state is not being updated correctly. This is a known issue in the MongoDB v2 connector, and a fix is being tested in newer builds ([see this comment for a test build](https://github.com/airbytehq/airbyte/issues/62833)). You may want to try upgrading to a version with this fix or monitor the state in Airbyte to see if the resume token is advancing as expected. If you continue to experience this issue, you may need to manually update the state or reset the connection as a temporary workaround, but a connector upgrade is recommended once the fix is released.
i
@kapa.ai im not having a saved offset not valid, my syncs are working fine, it's just that there is no new dat abeing updated
k
A message from kapa.ai
Thank you for clarifying that you are not seeing "saved offset not valid" errors and your syncs are running successfully, but no new data is being updated. Based on the knowledge sources, here are the most likely reasons for this behavior: 1. Cursor Field and Incremental Sync Logic Airbyte incremental syncs rely on a cursor field (in your case, managed internally, such as a resume token or oplog position). After the initial sync, only records with a cursor value greater than the last synced value are picked up. If no new records in your source collections have a cursor value (e.g., oplog timestamp or change event) greater than the last one Airbyte has seen, then no new data will be synced—even if new documents are added, if they do not trigger the expected change events or if the connector is not detecting them as new. This is a common scenario described in the documentation and forum posts, where users see "0 records loaded" after the first sync if the cursor logic does not match the data changes [Forum Post: Mongodb incremental + append - no row after first sync](https://discuss.airbyte.io/t/1641). 2. No New Changes Detected If your collections are not being updated or inserted with new data that the connector can detect (i.e., no new oplog/change stream events for the relevant collections), then Airbyte will not sync any new records. This can happen if: - No new documents are being inserted. - Inserts/updates are not being captured by the oplog/change stream (e.g., due to collection configuration or permissions). - The connector is not configured to watch the correct collections. 3. Connector Limitations There are no indications in the knowledge sources that the connector would silently skip new data unless the above conditions are met. If the oplog retention or resume token were an issue, you would typically see errors, not just empty syncs [Connector Limitations](https://docs.airbyte.com/integrations/sources/mongodb-v2/mongodb-v2-troubleshooting#connector-limitations). What you can do: - Double-check that new documents are actually being inserted into the source collections after the initial sync. - Ensure that the connector is configured to watch the correct collections and that those collections are being updated. - If possible, manually insert a new document into a watched collection and trigger a sync to see if it is picked up. If you confirm that new data is being added and still not synced, and there are no errors, the knowledge sources do not provide further troubleshooting steps for this specific scenario. In that case, you may want to review the Airbyte logs for any subtle warnings or reach out to the Airbyte community for more targeted support. If you have more details about your data insertion process or collection configuration, please share them for further analysis.
i
@kapa.ai please confirm that if CDC is enabledm then in te airbyte postgresdb when I run SELECT * FROM state the type should be other than GLOBAL, or GLOBAL is ok ?
k
A message from kapa.ai
If CDC is enabled, it is expected and correct for the state type in the Airbyte Postgres
state
table to be
GLOBAL
for some connectors. This is because, in CDC scenarios (such as log-based replication), the state often needs to track a global position in the database log (like an oplog or WAL position) that applies across multiple streams or collections. The Airbyte protocol specifically notes that the
GLOBAL
state type is used when there is shared state across streams, which is typical for CDC implementations: > The
GLOBAL
case allows the author of a Source to share state across streams (
shared_state
). This message should only be used in cases where there is a shared state across streams (e.g. CDC where the WAL log number is a global cursor), otherwise prefer
STREAM
 [Airbyte Protocol: State Types](https://docs.airbyte.com/platform/next/understanding-airbyte/airbyte-protocol#state-types). So, seeing
GLOBAL
as the state type in your
state
table is normal and expected when CDC is enabled.
i
@kapa.ai What is the differnece betweek LOOKUP and POST IMAGE data capture mode for mongo DB
k
A message from kapa.ai
The difference between LOOKUP and POST IMAGE data capture modes for MongoDB in Airbyte is as follows: - LOOKUP: In this mode, when a change event (such as an update) is detected, Airbyte performs a lookup to fetch the latest version of the document from the database. This ensures that the most current state of the document is captured, even if the change event itself does not contain the full document. - POST IMAGE: This mode relies on MongoDB's ability to return the "post image" of a document directly in the change stream event. The "post image" is the state of the document after the change. This mode is only supported in MongoDB version 6.0+ and requires that the collections of interest are configured to return pre and post images. If not properly configured, using this mode can lead to data loss. Important notes: - "Post image" mode requires MongoDB 6.0+ and specific collection setup. - If not configured correctly, "post image" mode can result in missing data. Reference: [MongoDB v2 Source Connector Documentation](https://docs.airbyte.com/integrations/sources/mongodb-v2#configuration-parameters)
t
Hey @Iulian did the new build fix it for you?
i
So data got synced eventually without any changes, I suspect this was not an airbyte issue but rather a Mongo Issue.
@Tanuj Shriyan Also on other environments the same configuration was working perfectly, no gaps in syncs, so agains confirm it was specific to the mongo cluster It was connecting to
t
@Iulian Is it possible for you to share the configuration hiding the confidential information on airbyte. Also, what's the oplog settings for you on mongodb? Has your incremental load working regularly after the new build, ours is failing after 2 days.
i
Nothing fancy I'm using the standard configuration on the connection source and destination that you find in terraform, literrally no difference. We're using incremental syncs and we're syncing every half hour. INcreasing the frequency of syncs will help you resolve the oplog window error