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 {
179
179
180
180
// We need to get the snapshot time before taking the initial snapshot.
181
181
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 ) {
189
188
throw new ServiceError (
190
189
ErrorCode . PSYNC_S1342 ,
191
190
'Standalone MongoDB instances are not supported - use a replicaset.'
192
191
) ;
193
- } else if ( snapshotTime == null ) {
192
+ }
193
+
194
+ if ( snapshotTime == null ) {
194
195
// Not known where this would happen apart from the above cases
195
196
throw new ReplicationAssertionError ( 'MongoDB lastWrite timestamp not found.' ) ;
196
197
}
198
+
197
199
// We previously used {snapshot: true} for the snapshot session.
198
200
// While it gives nice consistency guarantees, it fails when the
199
201
// snapshot takes longer than 5 minutes, due to minSnapshotHistoryWindowInSeconds
Original file line number Diff line number Diff line change 1
1
import { ErrorCode , ServiceError } from '@powersync/lib-services-framework' ;
2
- import { MongoManager } from './MongoManager.js' ;
3
2
import { PostImagesOption } from '../types/types.js' ;
3
+ import { MongoManager } from './MongoManager.js' ;
4
4
5
5
export const CHECKPOINTS_COLLECTION = '_powersync_checkpoints' ;
6
6
@@ -10,12 +10,9 @@ export async function checkSourceConfiguration(connectionManager: MongoManager):
10
10
const db = connectionManager . db ;
11
11
12
12
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 ) {
19
16
throw new ServiceError ( ErrorCode . PSYNC_S1342 , 'Standalone MongoDB instances are not supported - use a replicaset.' ) ;
20
17
}
21
18
You can’t perform that action at this time.
0 commit comments