Missing some Mongo data in your data warehouse? Due to how Mongo sorts data based on data type, Stitch may be unable to correctly identify new and updated data. If you don’t see data that you’d expect to, the root cause may be multiple data types in the table’s Replication Key field.
Here’s an example of multiple data types in the Replication Key field can cause data discrepancies:
- You sync a table, using a field called
table_idas the Replication Key. This field contains both
- A historical sync of the table completes.
- Because Mongo considers
ObjectIddata types to be greater than
Strings, Stitch will record the
MAXvalue as the last replicated record containing an
ObjectIddata type in the Replication Key field.
- New records are added to the table.
- During the next sync, Stitch uses the last recorded
MAXvalue - in this case, an
ObjectId- to identify new/updated data. Remember: only records with Replication Key values greater than or equal to this value will be selected for replication.
ObjectIds > Strings, all records with
Stringsare considered to be less than the last recorded
MAXvalue. This means Stitch won’t be able to detect these records and replicate them to your data warehouse.
Check for Multiple Data Types
To determine if a field has more than one data type, we recommend running the following queries. We’re using Mongo version 3.0+, so keep in mind that these queries may be different for your version.
Run this query to count how many of a single data type there are in the table’s Replication Key field, replacing:
nameOfCollectionwith the table name,
replicationKeyFieldwith the field name, and
knownDataTypeIdwith the Mongo BSON data type ID. You can find the data type IDs here in Mongo’s docs.
Next, run this query to get a count of all records in the table:
Compare the results. If the counts are equal, then the Replication Key field contains only one data type.
Additionally, the following query will return the
MAX value for the table’s Replication Key field. This can be helpful when comparing your source database to what’s in your data warehouse:
If Collection Count ≠ Data Type Count
If the results of the data type and total record counts aren’t equal, multiple data types in the Replication Key field may be interfering with Stitch’s replication process. Resolving this issue may require a full re-sync of the problem table.
If Collection Count = Data Type Count
If the results of the data type and total record counts queries are equal, then the root cause may not be multiple data types and further investigation is needed.
Before Contacting Support
Before reaching out to support, we recommend using the Data Discrepancy Troubleshooting Guide to further investigate the problem if you haven’t already. Providing us with the information from the queries in this article as well as the guide will help us pinpoint the issue more quickly.