Skip to content

Database options connect fix #8470

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

Closed
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions spec/GridFSBucketStorageAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ 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();

// connection will fail if unsupported keys are
// passed into the mongo connection options
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 @@ -20,7 +20,7 @@ export class GridFSBucketAdapter extends FilesAdapter {

constructor(
mongoDatabaseURI = defaults.DefaultMongoURI,
mongoOptions = {},
databaseOptions = {},
encryptionKey = undefined
) {
super();
Expand All @@ -34,6 +34,10 @@ export class GridFSBucketAdapter extends FilesAdapter {
useNewUrlParser: true,
useUnifiedTopology: true,
};
const mongoOptions = { ...databaseOptions };
for (const key of ['enableSchemaHooks', 'schemaCacheTtl', 'maxTimeMS']) {
delete mongoOptions[key];
}
this._mongoOptions = Object.assign(defaultMongoOptions, mongoOptions);
}

Expand Down