@@ -20,6 +20,8 @@ import { MongoManager } from './MongoManager.js';
2020import { constructAfterRecord , createCheckpoint , getMongoRelation , STANDALONE_CHECKPOINT_ID } from './MongoRelation.js' ;
2121import { ChunkedSnapshotQuery } from './MongoSnapshotQuery.js' ;
2222import { CHECKPOINTS_COLLECTION } from './replication-utils.js' ;
23+ import { staticFilterToMongoExpression } from './staticFilters.js' ;
24+ import { JSONBig } from '@powersync/service-jsonbig' ;
2325
2426export interface MongoSnapshotterOptions {
2527 connections : MongoManager ;
@@ -281,19 +283,22 @@ export class MongoSnapshotter {
281283 let at = table . snapshotStatus ?. replicatedCount ?? 0 ;
282284 const db = this . client . db ( table . schema ) ;
283285 const collection = db . collection ( table . name ) ;
284- console . log ( 'snapshot with filter' , table . pattern ?. filter , table . pattern ) ;
286+
287+ const mongoFilter = table . pattern ?. filter ? staticFilterToMongoExpression ( table . pattern . filter ) : null ;
288+ const filterLog = mongoFilter ? ` | filter: ${ JSONBig . stringify ( mongoFilter ) } ` : '' ;
289+
285290 await using query = new ChunkedSnapshotQuery ( {
286291 collection,
287292 key : table . snapshotStatus ?. lastKey ,
288293 batchSize : this . snapshotChunkLength ,
289- filter : table . pattern ?. filter
294+ filter : mongoFilter
290295 } ) ;
291296 if ( query . lastKey != null ) {
292297 this . logger . info (
293- `Replicating ${ table . qualifiedName } ${ table . formatSnapshotProgress ( ) } - resuming at _id > ${ query . lastKey } `
298+ `Replicating ${ table . qualifiedName } ${ table . formatSnapshotProgress ( ) } - resuming at _id > ${ query . lastKey } ${ filterLog } `
294299 ) ;
295300 } else {
296- this . logger . info ( `Replicating ${ table . qualifiedName } ${ table . formatSnapshotProgress ( ) } ` ) ;
301+ this . logger . info ( `Replicating ${ table . qualifiedName } ${ table . formatSnapshotProgress ( ) } ${ filterLog } ` ) ;
297302 }
298303
299304 let lastBatch = performance . now ( ) ;
@@ -355,21 +360,6 @@ export class MongoSnapshotter {
355360 return rowProcessor . applyRowContext < never > ( inputRow ) ;
356361 }
357362
358- private async getCollectionInfo ( db : string , name : string ) : Promise < mongo . CollectionInfo | undefined > {
359- const collection = (
360- await this . client
361- . db ( db )
362- . listCollections (
363- {
364- name : name
365- } ,
366- { nameOnly : false }
367- )
368- . toArray ( )
369- ) [ 0 ] ;
370- return collection ;
371- }
372-
373363 private async checkPostImages ( db : string , collectionInfo : mongo . CollectionInfo ) {
374364 if ( ! this . usePostImages ) {
375365 // Nothing to check
0 commit comments