From 982755c73acc0ddc6baea3482c2c2d61172679ac Mon Sep 17 00:00:00 2001 From: Omair Vaiyani Date: Wed, 8 Mar 2023 10:25:04 +0000 Subject: [PATCH 1/2] Remove unsupported db options from mongo connection --- spec/GridFSBucketStorageAdapter.spec.js | 19 +++++++++++++++++++ src/Adapters/Files/GridFSBucketAdapter.js | 6 +++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/GridFSBucketStorageAdapter.spec.js b/spec/GridFSBucketStorageAdapter.spec.js index 419bfdb98d8..8d51a4a0c33 100644 --- a/spec/GridFSBucketStorageAdapter.spec.js +++ b/spec/GridFSBucketStorageAdapter.spec.js @@ -20,6 +20,25 @@ describe_only_db('mongo')('GridFSBucket', () => { await db.dropDatabase(); }); + it('should connect to mongo with the supported database options', async () => { + const databaseURI = 'mongodb://localhost:27017/parse'; + const gfsAdapter = new GridFSBucketAdapter(databaseURI, { + retryWrites: true, + // these are not supported by mongo + enableSchemaHooks: true, + schemaCacheTtl: 5000, + }); + + const db = await gfsAdapter._connect(); + const status = await db.admin().serverStatus(); + + // connection will fail if unsupported keys are + // passed into the mongo connection options + expect(status.connections.current > 0).toEqual(true); + + expect(db.options?.retryWrites).toEqual(true); + }); + it('should save an encrypted file that can only be decrypted by a GridFS adapter with the encryptionKey', async () => { const unencryptedAdapter = new GridFSBucketAdapter(databaseURI); const encryptedAdapter = new GridFSBucketAdapter( diff --git a/src/Adapters/Files/GridFSBucketAdapter.js b/src/Adapters/Files/GridFSBucketAdapter.js index f2b9c48fadd..1f31d70fa4e 100644 --- a/src/Adapters/Files/GridFSBucketAdapter.js +++ b/src/Adapters/Files/GridFSBucketAdapter.js @@ -20,7 +20,7 @@ export class GridFSBucketAdapter extends FilesAdapter { constructor( mongoDatabaseURI = defaults.DefaultMongoURI, - mongoOptions = {}, + databaseOptions = {}, encryptionKey = undefined ) { super(); @@ -34,6 +34,10 @@ export class GridFSBucketAdapter extends FilesAdapter { useNewUrlParser: true, useUnifiedTopology: true, }; + const mongoOptions = { ...databaseOptions }; + for (const key of ['enableSchemaHooks', 'schemaCacheTtl']) { + delete mongoOptions[key]; + } this._mongoOptions = Object.assign(defaultMongoOptions, mongoOptions); } From 9c622efa1532ff4455352da35db1da4f0e3c1d80 Mon Sep 17 00:00:00 2001 From: Omair Vaiyani Date: Wed, 8 Mar 2023 10:29:27 +0000 Subject: [PATCH 2/2] Add maxTimeMS to filter list --- spec/GridFSBucketStorageAdapter.spec.js | 3 ++- src/Adapters/Files/GridFSBucketAdapter.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/GridFSBucketStorageAdapter.spec.js b/spec/GridFSBucketStorageAdapter.spec.js index 8d51a4a0c33..01373234954 100644 --- a/spec/GridFSBucketStorageAdapter.spec.js +++ b/spec/GridFSBucketStorageAdapter.spec.js @@ -24,9 +24,10 @@ describe_only_db('mongo')('GridFSBucket', () => { const databaseURI = 'mongodb://localhost:27017/parse'; const gfsAdapter = new GridFSBucketAdapter(databaseURI, { retryWrites: true, - // these are not supported by mongo + // these are not supported by the mongo client enableSchemaHooks: true, schemaCacheTtl: 5000, + maxTimeMS: 30000, }); const db = await gfsAdapter._connect(); diff --git a/src/Adapters/Files/GridFSBucketAdapter.js b/src/Adapters/Files/GridFSBucketAdapter.js index 1f31d70fa4e..14a9544fc27 100644 --- a/src/Adapters/Files/GridFSBucketAdapter.js +++ b/src/Adapters/Files/GridFSBucketAdapter.js @@ -35,7 +35,7 @@ export class GridFSBucketAdapter extends FilesAdapter { useUnifiedTopology: true, }; const mongoOptions = { ...databaseOptions }; - for (const key of ['enableSchemaHooks', 'schemaCacheTtl']) { + for (const key of ['enableSchemaHooks', 'schemaCacheTtl', 'maxTimeMS']) { delete mongoOptions[key]; } this._mongoOptions = Object.assign(defaultMongoOptions, mongoOptions);