|
## Incremental Sync Pattern |
|
|
|
A common pattern for syncing data to another system: |
|
|
|
```javascript |
|
async function syncChanges(lastSyncTime) { |
|
const cursor = db.collection("products").find( |
|
{ updatedAt: { $gt: lastSyncTime } }, |
|
{ sort: { updatedAt: 1 } } |
|
); |
|
|
|
const changes = await cursor.toArray(); |
|
// process changes... |
|
|
|
const newSyncTime = changes.length > 0 |
|
? changes[changes.length - 1].updatedAt |
|
: lastSyncTime; |
|
|
|
return newSyncTime; |
|
} |
|
``` |
This will not work correclty even with Read concern: "linearizable".
What are compatible read and write concerns?
blog/posts/2026-03-31-mongodb-query-documents-updated-after-specific-time/README.md
Lines 113 to 133 in ef9de12
This will not work correclty even with Read concern: "linearizable".
What are compatible read and write concerns?