diff --git a/src/plugins/replication-firestore/index.ts b/src/plugins/replication-firestore/index.ts index 389b9d8053c..3eab5ffcacc 100644 --- a/src/plugins/replication-firestore/index.ts +++ b/src/plugins/replication-firestore/index.ts @@ -138,8 +138,8 @@ export function replicateFirestore( ); sameTimeQuery = query(pullQuery, where(serverTimestampField, '==', lastServerTimestamp), - where(primaryPath, '>', lastPulledCheckpoint.id), - orderBy(primaryPath, 'asc'), + where(documentId(), '>', lastPulledCheckpoint.id), + orderBy(documentId(), 'asc'), limit(batchSize) ); } else { diff --git a/test/replication-firestore.test.ts b/test/replication-firestore.test.ts index 2c283766d36..e9aacad2772 100644 --- a/test/replication-firestore.test.ts +++ b/test/replication-firestore.test.ts @@ -420,5 +420,40 @@ describe('replication-firestore.test.ts', function () { collection.database.destroy(); }); + it('replicates all docs with identical serverTimestamp from the server', async () => { + const firestoreState = getFirestoreState(); + const collection = await humansCollection.create(0); + + const now = new Date(); + const h1 = { + ...makeFirestoreHumanDocument( + schemaObjects.humanData('replicated-1', 35, 'replicated') + ), + serverTimestamp: now, + }; + const h2 = { + ...makeFirestoreHumanDocument( + schemaObjects.humanData('replicated-2', 27, 'replicated') + ), + serverTimestamp: now, + }; + + await setDoc(DocRef(firestoreState.collection, 'replicated-1'), h1); + await setDoc(DocRef(firestoreState.collection, 'replicated-2'), h2); + + await syncOnce(collection, firestoreState, { + pull: { + batchSize: 1, + }, + push: {}, + }); + + const allLocalDocs = await collection.find().exec(); + + assert.strictEqual(allLocalDocs.length, 2); + + collection.database.destroy(); + }); + }); });