Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: custom database options are not passed to MongoDB GridFS #7911

Merged
merged 5 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions spec/FilesController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ describe('FilesController', () => {
done();
});

it_only_db('mongo')('should pass databaseOptions to GridFSBucketAdapter', async () => {
await reconfigureServer({
databaseURI: 'mongodb://localhost:27017/parse',
filesAdapter: null,
databaseAdapter: null,
databaseOptions: {
retryWrites: true,
},
});
const config = Config.get(Parse.applicationId);
expect(config.database.adapter._mongoOptions.retryWrites).toBeTrue();
expect(config.filesController.adapter._mongoOptions.retryWrites).toBeTrue();
});

it('should create a server log on failure', done => {
const logController = new LoggerController(new WinstonLoggerAdapter());

Expand Down
12 changes: 10 additions & 2 deletions src/Controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,20 @@ export function getLoggerController(options: ParseServerOptions): LoggerControll
}

export function getFilesController(options: ParseServerOptions): FilesController {
const { appId, databaseURI, filesAdapter, databaseAdapter, preserveFileName, fileKey } = options;
const {
appId,
databaseURI,
databaseOptions = {},
filesAdapter,
databaseAdapter,
preserveFileName,
fileKey,
} = options;
if (!filesAdapter && databaseAdapter) {
throw 'When using an explicit database adapter, you must also use an explicit filesAdapter.';
}
const filesControllerAdapter = loadAdapter(filesAdapter, () => {
return new GridFSBucketAdapter(databaseURI, {}, fileKey);
return new GridFSBucketAdapter(databaseURI, databaseOptions, fileKey);
});
return new FilesController(filesControllerAdapter, appId, {
preserveFileName,
Expand Down