Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-doors-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/service-module-mongodb': minor
---

Added progress logs to initial snapshot
9 changes: 6 additions & 3 deletions modules/module-mongodb/src/replication/ChangeStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class ChangeStream {

async estimatedCount(table: storage.SourceTable): Promise<string> {
const db = this.client.db(table.schema);
const count = db.collection(table.table).estimatedDocumentCount();
const count = await db.collection(table.table).estimatedDocumentCount();
return `~${count}`;
}

Expand Down Expand Up @@ -298,6 +298,7 @@ export class ChangeStream {
logger.info(`Replicating ${table.qualifiedName}`);
const estimatedCount = await this.estimatedCount(table);
let at = 0;
let lastLogIndex = 0;

const db = this.client.db(table.schema);
const collection = db.collection(table.table);
Expand All @@ -310,8 +311,6 @@ export class ChangeStream {
throw new ReplicationAbortedError(`Aborted initial replication`);
}

at += 1;

const record = constructAfterRecord(document);

// This auto-flushes when the batch reaches its size limit
Expand All @@ -325,6 +324,10 @@ export class ChangeStream {
});

at += 1;
if (at - lastLogIndex >= 5000) {
logger.info(`[${this.group_id}] Replicating ${table.qualifiedName} ${at}/${estimatedCount}`);
lastLogIndex = at;
}
Metrics.getInstance().rows_replicated_total.add(1);

await touch();
Expand Down