File tree Expand file tree Collapse file tree 3 files changed +21
-15
lines changed
modules/module-mongodb/src/replication Expand file tree Collapse file tree 3 files changed +21
-15
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @powersync/service-module-mongodb ' : minor
3+ ' @powersync/service-core ' : minor
4+ ' @powersync/service-image ' : minor
5+ ---
6+
7+ Added support for sharded MongoDB replication connections.
Original file line number Diff line number Diff line change @@ -179,21 +179,23 @@ export class ChangeStream {
179179
180180 // We need to get the snapshot time before taking the initial snapshot.
181181 const hello = await this . defaultDb . command ( { hello : 1 } ) ;
182- const snapshotTime = hello . lastWrite ?. majorityOpTime ?. ts as mongo . Timestamp ;
183- if ( hello . msg == 'isdbgrid' ) {
184- throw new ServiceError (
185- ErrorCode . PSYNC_S1341 ,
186- 'Sharded MongoDB Clusters are not supported yet (including MongoDB Serverless instances).'
187- ) ;
188- } else if ( hello . setName == null ) {
182+ // Use the clusterTime for sharded clusters
183+ const snapshotTime : mongo . Timestamp = hello . lastWrite ?. majorityOpTime ?. ts ?? hello . $clusterTime ?. clusterTime ;
184+
185+ // Sharded cluster don't provide a setName, but we do support them.
186+ // We don't support standalone instances
187+ if ( hello . msg != 'isdbgrid' && hello . setName == null ) {
189188 throw new ServiceError (
190189 ErrorCode . PSYNC_S1342 ,
191190 'Standalone MongoDB instances are not supported - use a replicaset.'
192191 ) ;
193- } else if ( snapshotTime == null ) {
192+ }
193+
194+ if ( snapshotTime == null ) {
194195 // Not known where this would happen apart from the above cases
195196 throw new ReplicationAssertionError ( 'MongoDB lastWrite timestamp not found.' ) ;
196197 }
198+
197199 // We previously used {snapshot: true} for the snapshot session.
198200 // While it gives nice consistency guarantees, it fails when the
199201 // snapshot takes longer than 5 minutes, due to minSnapshotHistoryWindowInSeconds
Original file line number Diff line number Diff line change 11import { ErrorCode , ServiceError } from '@powersync/lib-services-framework' ;
2- import { MongoManager } from './MongoManager.js' ;
32import { PostImagesOption } from '../types/types.js' ;
3+ import { MongoManager } from './MongoManager.js' ;
44
55export const CHECKPOINTS_COLLECTION = '_powersync_checkpoints' ;
66
@@ -10,12 +10,9 @@ export async function checkSourceConfiguration(connectionManager: MongoManager):
1010 const db = connectionManager . db ;
1111
1212 const hello = await db . command ( { hello : 1 } ) ;
13- if ( hello . msg == 'isdbgrid' ) {
14- throw new ServiceError (
15- ErrorCode . PSYNC_S1341 ,
16- 'Sharded MongoDB Clusters are not supported yet (including MongoDB Serverless instances).'
17- ) ;
18- } else if ( hello . setName == null ) {
13+ // Sharded cluster don't provide a setName, but we do support them.
14+ // We don't support standalone instances
15+ if ( hello . msg != 'isdbgrid' && hello . setName == null ) {
1916 throw new ServiceError ( ErrorCode . PSYNC_S1342 , 'Standalone MongoDB instances are not supported - use a replicaset.' ) ;
2017 }
2118
You can’t perform that action at this time.
0 commit comments