Skip to content

Commit 5a0eb8e

Browse files
committed
fix defaults injection for databaseOptions
1 parent 7b6f4b4 commit 5a0eb8e

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

spec/MongoStorageAdapter.spec.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,14 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
142142
expect(results.length).toEqual(3);
143143
});
144144

145-
it('defaults batchSize to undefined when not configured', () => {
146-
const adapter = new MongoStorageAdapter({
147-
uri: databaseURI,
145+
it('defaults batchSize to 1000', async () => {
146+
await reconfigureServer({
147+
databaseURI: databaseURI,
148+
collectionPrefix: 'test_',
149+
databaseAdapter: undefined,
148150
});
149-
expect(adapter._batchSize).toBeUndefined();
151+
const adapter = Config.get(Parse.applicationId).database.adapter;
152+
expect(adapter._batchSize).toEqual(1000);
150153
});
151154

152155
it('stores pointers with a _p_ prefix', done => {

src/ParseServer.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var batch = require('./batch'),
99
fs = require('fs');
1010

1111
import { ParseServerOptions, LiveQueryServerOptions } from './Options';
12-
import defaults from './defaults';
12+
import defaults, { DatabaseOptionDefaults } from './defaults';
1313
import * as logging from './logger';
1414
import Config from './Config';
1515
import PromiseRouter from './PromiseRouter';
@@ -593,6 +593,20 @@ function injectDefaults(options: ParseServerOptions) {
593593
}
594594
});
595595

596+
// Inject defaults for database options; only when no explicit database adapter is set,
597+
// because an explicit adapter manages its own options and passing databaseOptions alongside
598+
// it would cause a conflict error in getDatabaseController.
599+
if (!options.databaseAdapter) {
600+
if (!options.databaseOptions) {
601+
options.databaseOptions = {};
602+
}
603+
Object.keys(DatabaseOptionDefaults).forEach(key => {
604+
if (!Object.prototype.hasOwnProperty.call(options.databaseOptions, key)) {
605+
options.databaseOptions[key] = DatabaseOptionDefaults[key];
606+
}
607+
});
608+
}
609+
596610
if (!Object.prototype.hasOwnProperty.call(options, 'serverURL')) {
597611
options.serverURL = `http://localhost:${options.port}${options.mountPath}`;
598612
}

src/defaults.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { nullParser } from './Options/parsers';
2-
const { ParseServerOptions } = require('./Options/Definitions');
2+
const { ParseServerOptions, DatabaseOptions } = require('./Options/Definitions');
33
const logsFolder = (() => {
44
let folder = './logs/';
55
if (typeof process !== 'undefined' && process.env.TESTING === '1') {
@@ -34,6 +34,14 @@ const computedDefaults = {
3434
export default Object.assign({}, DefinitionDefaults, computedDefaults);
3535
export const DefaultMongoURI = DefinitionDefaults.databaseURI;
3636

37+
export const DatabaseOptionDefaults = Object.keys(DatabaseOptions).reduce((memo, key) => {
38+
const def = DatabaseOptions[key];
39+
if (Object.prototype.hasOwnProperty.call(def, 'default')) {
40+
memo[key] = def.default;
41+
}
42+
return memo;
43+
}, {});
44+
3745
// Parse Server-specific database options that should be filtered out
3846
// before passing to MongoDB client
3947
export const ParseServerDatabaseOptions = [

0 commit comments

Comments
 (0)