Skip to content

Commit d4cda4b

Browse files
authored
fix: GridFS file storage doesn't work with certain enableSchemaHooks settings (#8467)
1 parent c78a5a6 commit d4cda4b

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

spec/FilesController.spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ describe('FilesController', () => {
5555
const config = Config.get(Parse.applicationId);
5656
expect(config.database.adapter._mongoOptions.retryWrites).toBeTrue();
5757
expect(config.filesController.adapter._mongoOptions.retryWrites).toBeTrue();
58+
expect(config.filesController.adapter._mongoOptions.enableSchemaHooks).toBeUndefined();
59+
expect(config.filesController.adapter._mongoOptions.schemaCacheTtl).toBeUndefined();
5860
});
5961

6062
it('should create a server log on failure', done => {

spec/GridFSBucketStorageAdapter.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ 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+
expect(status.connections.current > 0).toEqual(true);
36+
expect(db.options?.retryWrites).toEqual(true);
37+
});
38+
2339
it('should save an encrypted file that can only be decrypted by a GridFS adapter with the encryptionKey', async () => {
2440
const unencryptedAdapter = new GridFSBucketAdapter(databaseURI);
2541
const encryptedAdapter = new GridFSBucketAdapter(

src/Adapters/Files/GridFSBucketAdapter.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ export class GridFSBucketAdapter extends FilesAdapter {
3434
useNewUrlParser: true,
3535
useUnifiedTopology: true,
3636
};
37-
this._mongoOptions = Object.assign(defaultMongoOptions, mongoOptions);
37+
const _mongoOptions = Object.assign(defaultMongoOptions, mongoOptions);
38+
for (const key of ['enableSchemaHooks', 'schemaCacheTtl', 'maxTimeMS']) {
39+
delete _mongoOptions[key];
40+
}
41+
this._mongoOptions = _mongoOptions;
3842
}
3943

4044
_connect() {

0 commit comments

Comments
 (0)