Skip to content

Commit dc5bf00

Browse files
committed
centralize
1 parent e1802e0 commit dc5bf00

File tree

3 files changed

+29
-38
lines changed

3 files changed

+29
-38
lines changed

src/Adapters/Files/GridFSBucketAdapter.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// @flow-disable-next
1010
import { MongoClient, GridFSBucket, Db } from 'mongodb';
1111
import { FilesAdapter, validateFilename } from './FilesAdapter';
12-
import defaults from '../../defaults';
12+
import defaults, { ParseServerDatabaseOptions } from '../../defaults';
1313
const crypto = require('crypto');
1414

1515
export class GridFSBucketAdapter extends FilesAdapter {
@@ -34,24 +34,10 @@ export class GridFSBucketAdapter extends FilesAdapter {
3434
.digest('base64')
3535
.substring(0, 32)
3636
: null;
37-
const defaultMongoOptions = {
38-
};
37+
const defaultMongoOptions = {};
3938
const _mongoOptions = Object.assign(defaultMongoOptions, mongoOptions);
40-
for (const key of [
41-
'allowPublicExplain',
42-
'enableSchemaHooks',
43-
'schemaCacheTtl',
44-
'maxTimeMS',
45-
'disableIndexFieldValidation',
46-
'logClientEvents',
47-
'createIndexUserUsername',
48-
'createIndexUserUsernameCaseInsensitive',
49-
'createIndexUserEmail',
50-
'createIndexUserEmailCaseInsensitive',
51-
'createIndexUserEmailVerifyToken',
52-
'createIndexUserPasswordResetToken',
53-
'createIndexRoleName',
54-
]) {
39+
// Remove Parse Server-specific options that should not be passed to MongoDB client
40+
for (const key of ParseServerDatabaseOptions) {
5541
delete _mongoOptions[key];
5642
}
5743
this._mongoOptions = _mongoOptions;

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import Parse from 'parse/node';
1717
// @flow-disable-next
1818
import _ from 'lodash';
19-
import defaults from '../../../defaults';
19+
import defaults, { ParseServerDatabaseOptions } from '../../../defaults';
2020
import logger from '../../../logger';
2121
import Utils from '../../../Utils';
2222

@@ -147,7 +147,6 @@ export class MongoStorageAdapter implements StorageAdapter {
147147
constructor({ uri = defaults.DefaultMongoURI, collectionPrefix = '', mongoOptions = {} }: any) {
148148
this._uri = uri;
149149
this._collectionPrefix = collectionPrefix;
150-
this._mongoOptions = { ...mongoOptions };
151150
this._onchange = () => {};
152151

153152
// MaxTimeMS is not a global MongoDB client option, it is applied per operation.
@@ -158,24 +157,12 @@ export class MongoStorageAdapter implements StorageAdapter {
158157
this.disableIndexFieldValidation = !!mongoOptions.disableIndexFieldValidation;
159158
this._logClientEvents = mongoOptions.logClientEvents;
160159

161-
// Remove Parse Server-specific options that should not be passed to MongoDB client
162-
// Note: We only delete from this._mongoOptions, not from the original mongoOptions object,
163-
// because other components (like DatabaseController) need access to these options
164-
for (const key of [
165-
'allowPublicExplain',
166-
'enableSchemaHooks',
167-
'schemaCacheTtl',
168-
'maxTimeMS',
169-
'disableIndexFieldValidation',
170-
'logClientEvents',
171-
'createIndexUserUsername',
172-
'createIndexUserUsernameCaseInsensitive',
173-
'createIndexUserEmail',
174-
'createIndexUserEmailCaseInsensitive',
175-
'createIndexUserEmailVerifyToken',
176-
'createIndexUserPasswordResetToken',
177-
'createIndexRoleName',
178-
]) {
160+
// Create a copy of mongoOptions and remove Parse Server-specific options that should not
161+
// be passed to MongoDB client. Note: We only delete from this._mongoOptions, not from the
162+
// original mongoOptions object, because other components (like DatabaseController) need
163+
// access to these options.
164+
this._mongoOptions = { ...mongoOptions };
165+
for (const key of ParseServerDatabaseOptions) {
179166
delete this._mongoOptions[key];
180167
}
181168
}

src/defaults.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,21 @@ const computedDefaults = {
3333

3434
export default Object.assign({}, DefinitionDefaults, computedDefaults);
3535
export const DefaultMongoURI = DefinitionDefaults.databaseURI;
36+
37+
// Parse Server-specific database options that should be filtered out
38+
// before passing to MongoDB client
39+
export const ParseServerDatabaseOptions = [
40+
'allowPublicExplain',
41+
'enableSchemaHooks',
42+
'schemaCacheTtl',
43+
'maxTimeMS',
44+
'disableIndexFieldValidation',
45+
'logClientEvents',
46+
'createIndexUserUsername',
47+
'createIndexUserUsernameCaseInsensitive',
48+
'createIndexUserEmail',
49+
'createIndexUserEmailCaseInsensitive',
50+
'createIndexUserEmailVerifyToken',
51+
'createIndexUserPasswordResetToken',
52+
'createIndexRoleName',
53+
];

0 commit comments

Comments
 (0)