Skip to content

Commit 982755c

Browse files
committed
Remove unsupported db options from mongo connection
1 parent c4ce59c commit 982755c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

spec/GridFSBucketStorageAdapter.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ 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 mongo
28+
enableSchemaHooks: true,
29+
schemaCacheTtl: 5000,
30+
});
31+
32+
const db = await gfsAdapter._connect();
33+
const status = await db.admin().serverStatus();
34+
35+
// connection will fail if unsupported keys are
36+
// passed into the mongo connection options
37+
expect(status.connections.current > 0).toEqual(true);
38+
39+
expect(db.options?.retryWrites).toEqual(true);
40+
});
41+
2342
it('should save an encrypted file that can only be decrypted by a GridFS adapter with the encryptionKey', async () => {
2443
const unencryptedAdapter = new GridFSBucketAdapter(databaseURI);
2544
const encryptedAdapter = new GridFSBucketAdapter(

src/Adapters/Files/GridFSBucketAdapter.js

Lines changed: 5 additions & 1 deletion
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']) {
39+
delete mongoOptions[key];
40+
}
3741
this._mongoOptions = Object.assign(defaultMongoOptions, mongoOptions);
3842
}
3943

0 commit comments

Comments
 (0)