Skip to content

Commit ca37e39

Browse files
authored
Remove unsupported db options from mongo connection (#2)
* Remove unsupported db options from mongo connection * Add maxTimeMS to filter list
1 parent 6e91862 commit ca37e39

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

spec/GridFSBucketStorageAdapter.spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ describe_only_db('mongo')('GridFSBucket', () => {
2020
await db.dropDatabase();
2121
});
2222

23+
it('should connect to mongo with the supported database options', async () => {
24+
const databaseURI = 'mongodb://localhost:27017/parse';
25+
const gfsAdapter = new GridFSBucketAdapter(databaseURI, {
26+
retryWrites: true,
27+
// these are not supported by the mongo client
28+
enableSchemaHooks: true,
29+
schemaCacheTtl: 5000,
30+
maxTimeMS: 30000,
31+
});
32+
33+
const db = await gfsAdapter._connect();
34+
const status = await db.admin().serverStatus();
35+
36+
// connection will fail if unsupported keys are
37+
// passed into the mongo connection options
38+
expect(status.connections.current > 0).toEqual(true);
39+
40+
expect(db.options?.retryWrites).toEqual(true);
41+
});
42+
2343
it('should save an encrypted file that can only be decrypted by a GridFS adapter with the encryptionKey', async () => {
2444
const unencryptedAdapter = new GridFSBucketAdapter(databaseURI);
2545
const encryptedAdapter = new GridFSBucketAdapter(

src/Adapters/Files/GridFSBucketAdapter.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class GridFSBucketAdapter extends FilesAdapter {
2020

2121
constructor(
2222
mongoDatabaseURI = defaults.DefaultMongoURI,
23-
mongoOptions = {},
23+
databaseOptions = {},
2424
encryptionKey = undefined
2525
) {
2626
super();
@@ -34,6 +34,10 @@ export class GridFSBucketAdapter extends FilesAdapter {
3434
useNewUrlParser: true,
3535
useUnifiedTopology: true,
3636
};
37+
const mongoOptions = { ...databaseOptions };
38+
for (const key of ['enableSchemaHooks', 'schemaCacheTtl', 'maxTimeMS']) {
39+
delete mongoOptions[key];
40+
}
3741
this._mongoOptions = Object.assign(defaultMongoOptions, mongoOptions);
3842
}
3943

0 commit comments

Comments
 (0)