Skip to content

Commit

Permalink
fix: GridFS file storage doesn't work with certain `enableSchemaHooks…
Browse files Browse the repository at this point in the history
…` settings (#8467)
  • Loading branch information
dblythy authored May 19, 2023
1 parent c78a5a6 commit d4cda4b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions spec/FilesController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ describe('FilesController', () => {
const config = Config.get(Parse.applicationId);
expect(config.database.adapter._mongoOptions.retryWrites).toBeTrue();
expect(config.filesController.adapter._mongoOptions.retryWrites).toBeTrue();
expect(config.filesController.adapter._mongoOptions.enableSchemaHooks).toBeUndefined();
expect(config.filesController.adapter._mongoOptions.schemaCacheTtl).toBeUndefined();
});

it('should create a server log on failure', done => {
Expand Down
16 changes: 16 additions & 0 deletions spec/GridFSBucketStorageAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ 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 the mongo client
enableSchemaHooks: true,
schemaCacheTtl: 5000,
maxTimeMS: 30000,
});

const db = await gfsAdapter._connect();
const status = await db.admin().serverStatus();
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(
Expand Down
6 changes: 5 additions & 1 deletion src/Adapters/Files/GridFSBucketAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export class GridFSBucketAdapter extends FilesAdapter {
useNewUrlParser: true,
useUnifiedTopology: true,
};
this._mongoOptions = Object.assign(defaultMongoOptions, mongoOptions);
const _mongoOptions = Object.assign(defaultMongoOptions, mongoOptions);
for (const key of ['enableSchemaHooks', 'schemaCacheTtl', 'maxTimeMS']) {
delete _mongoOptions[key];
}
this._mongoOptions = _mongoOptions;
}

_connect() {
Expand Down

0 comments on commit d4cda4b

Please sign in to comment.