Skip to content
Merged
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
12 changes: 11 additions & 1 deletion spec/GridFSBucketStorageAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,20 @@ describe_only_db('mongo')('GridFSBucket', () => {
const databaseURI = 'mongodb://localhost:27017/parse';
const gfsAdapter = new GridFSBucketAdapter(databaseURI, {
retryWrites: true,
// these are not supported by the mongo client
// Parse Server-specific options that should be filtered out before passing to MongoDB client
allowPublicExplain: true,
enableSchemaHooks: true,
schemaCacheTtl: 5000,
maxTimeMS: 30000,
disableIndexFieldValidation: true,
logClientEvents: [{ name: 'commandStarted' }],
createIndexUserUsername: true,
createIndexUserUsernameCaseInsensitive: true,
createIndexUserEmail: true,
createIndexUserEmailCaseInsensitive: true,
createIndexUserEmailVerifyToken: true,
createIndexUserPasswordResetToken: true,
createIndexRoleName: true,
});

const db = await gfsAdapter._connect();
Expand Down
8 changes: 4 additions & 4 deletions src/Adapters/Files/GridFSBucketAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// @flow-disable-next
import { MongoClient, GridFSBucket, Db } from 'mongodb';
import { FilesAdapter, validateFilename } from './FilesAdapter';
import defaults from '../../defaults';
import defaults, { ParseServerDatabaseOptions } from '../../defaults';
const crypto = require('crypto');

export class GridFSBucketAdapter extends FilesAdapter {
Expand All @@ -34,10 +34,10 @@ export class GridFSBucketAdapter extends FilesAdapter {
.digest('base64')
.substring(0, 32)
: null;
const defaultMongoOptions = {
};
const defaultMongoOptions = {};
const _mongoOptions = Object.assign(defaultMongoOptions, mongoOptions);
for (const key of ['enableSchemaHooks', 'schemaCacheTtl', 'maxTimeMS', 'disableIndexFieldValidation']) {
// Remove Parse Server-specific options that should not be passed to MongoDB client
for (const key of ParseServerDatabaseOptions) {
delete _mongoOptions[key];
}
this._mongoOptions = _mongoOptions;
Expand Down
27 changes: 7 additions & 20 deletions src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import Parse from 'parse/node';
// @flow-disable-next
import _ from 'lodash';
import defaults from '../../../defaults';
import defaults, { ParseServerDatabaseOptions } from '../../../defaults';
import logger from '../../../logger';
import Utils from '../../../Utils';

Expand Down Expand Up @@ -147,7 +147,6 @@ export class MongoStorageAdapter implements StorageAdapter {
constructor({ uri = defaults.DefaultMongoURI, collectionPrefix = '', mongoOptions = {} }: any) {
this._uri = uri;
this._collectionPrefix = collectionPrefix;
this._mongoOptions = { ...mongoOptions };
this._onchange = () => {};

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

// Remove Parse Server-specific options that should not be passed to MongoDB client
// Note: We only delete from this._mongoOptions, not from the original mongoOptions object,
// because other components (like DatabaseController) need access to these options
for (const key of [
'allowPublicExplain',
'enableSchemaHooks',
'schemaCacheTtl',
'maxTimeMS',
'disableIndexFieldValidation',
'logClientEvents',
'createIndexUserUsername',
'createIndexUserUsernameCaseInsensitive',
'createIndexUserEmail',
'createIndexUserEmailCaseInsensitive',
'createIndexUserEmailVerifyToken',
'createIndexUserPasswordResetToken',
'createIndexRoleName',
]) {
// Create a copy of mongoOptions and remove Parse Server-specific options that should not
// be passed to MongoDB client. Note: We only delete from this._mongoOptions, not from the
// original mongoOptions object, because other components (like DatabaseController) need
// access to these options.
this._mongoOptions = { ...mongoOptions };
for (const key of ParseServerDatabaseOptions) {
delete this._mongoOptions[key];
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,21 @@ const computedDefaults = {

export default Object.assign({}, DefinitionDefaults, computedDefaults);
export const DefaultMongoURI = DefinitionDefaults.databaseURI;

// Parse Server-specific database options that should be filtered out
// before passing to MongoDB client
export const ParseServerDatabaseOptions = [
'allowPublicExplain',
'createIndexRoleName',
'createIndexUserEmail',
'createIndexUserEmailCaseInsensitive',
'createIndexUserEmailVerifyToken',
'createIndexUserPasswordResetToken',
'createIndexUserUsername',
'createIndexUserUsernameCaseInsensitive',
'disableIndexFieldValidation',
'enableSchemaHooks',
'logClientEvents',
'maxTimeMS',
'schemaCacheTtl',
];
16 changes: 13 additions & 3 deletions types/Options/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,28 @@ export interface FileUploadOptions {
}
export interface DatabaseOptions {
// Parse Server custom options
allowPublicExplain?: boolean;
createIndexRoleName?: boolean;
createIndexUserEmail?: boolean;
createIndexUserEmailCaseInsensitive?: boolean;
createIndexUserEmailVerifyToken?: boolean;
createIndexUserPasswordResetToken?: boolean;
createIndexUserUsername?: boolean;
createIndexUserUsernameCaseInsensitive?: boolean;
disableIndexFieldValidation?: boolean;
enableSchemaHooks?: boolean;
logClientEvents?: any[];
// maxTimeMS is a MongoDB option but Parse Server applies it per-operation, not as a global client option
maxTimeMS?: number;
schemaCacheTtl?: number;

// MongoDB driver options
appName?: string;
authMechanism?: string;
authMechanismProperties?: any;
authSource?: string;
autoSelectFamily?: boolean;
autoSelectFamilyAttemptTimeout?: number;
allowPublicExplain?: boolean;
compressors?: string[] | string;
connectTimeoutMS?: number;
directConnection?: boolean;
Expand All @@ -250,7 +261,6 @@ export interface DatabaseOptions {
maxIdleTimeMS?: number;
maxPoolSize?: number;
maxStalenessSeconds?: number;
maxTimeMS?: number;
minPoolSize?: number;
proxyHost?: string;
proxyPassword?: string;
Expand Down
Loading