Skip to content

Commit dbf2afc

Browse files
Add database options to ParseServer constructor and pass to MongoStorageAdapter
1 parent f08b0b3 commit dbf2afc

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@ const MongoSchemaCollectionName = '_SCHEMA';
1010
export class MongoStorageAdapter {
1111
// Private
1212
_uri: string;
13+
_options: Object;
1314
// Public
1415
connectionPromise;
1516
database;
1617

17-
constructor(uri: string) {
18+
constructor(uri: string, options: Object) {
1819
this._uri = uri;
20+
this._options = options;
1921
}
2022

2123
connect() {
2224
if (this.connectionPromise) {
2325
return this.connectionPromise;
2426
}
2527

26-
this.connectionPromise = MongoClient.connect(this._uri).then(database => {
28+
this.connectionPromise = MongoClient.connect(this._uri, this._options).then(database => {
2729
this.database = database;
2830
});
2931
return this.connectionPromise;

src/DatabaseAdapter.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ let adapter = MongoStorageAdapter;
2424
let dbConnections = {};
2525
let databaseURI = DefaultDatabaseURI;
2626
let appDatabaseURIs = {};
27+
let appDatabaseOptions = {};
2728

2829
function setAdapter(databaseAdapter) {
2930
adapter = databaseAdapter;
@@ -37,6 +38,10 @@ function setAppDatabaseURI(appId, uri) {
3738
appDatabaseURIs[appId] = uri;
3839
}
3940

41+
function setAppDatabaseOptions(appId: string, options: Object) {
42+
appDatabaseOptions[appId] = options;
43+
}
44+
4045
//Used by tests
4146
function clearDatabaseURIs() {
4247
appDatabaseURIs = {};
@@ -50,7 +55,7 @@ function getDatabaseConnection(appId: string, collectionPrefix: string) {
5055

5156
var dbURI = (appDatabaseURIs[appId] ? appDatabaseURIs[appId] : databaseURI);
5257

53-
let storageAdapter = new adapter(dbURI);
58+
let storageAdapter = new adapter(dbURI, appDatabaseOptions[appId]);
5459
dbConnections[appId] = new DatabaseController(storageAdapter, {
5560
collectionPrefix: collectionPrefix
5661
});
@@ -62,6 +67,7 @@ module.exports = {
6267
getDatabaseConnection: getDatabaseConnection,
6368
setAdapter: setAdapter,
6469
setDatabaseURI: setDatabaseURI,
70+
setAppDatabaseOptions: setAppDatabaseOptions,
6571
setAppDatabaseURI: setAppDatabaseURI,
6672
clearDatabaseURIs: clearDatabaseURIs,
6773
defaultDatabaseURI: databaseURI

src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function ParseServer({
8484
push,
8585
loggerAdapter,
8686
databaseURI = DatabaseAdapter.defaultDatabaseURI,
87+
databaseOptions,
8788
cloud,
8889
collectionPrefix = '',
8990
clientKey,
@@ -120,6 +121,10 @@ function ParseServer({
120121
DatabaseAdapter.setAppDatabaseURI(appId, databaseURI);
121122
}
122123

124+
if (databaseOptions) {
125+
DatabaseAdapter.setAppDatabaseOptions(appId, databaseOptions);
126+
}
127+
123128
if (cloud) {
124129
addParseCloud();
125130
if (typeof cloud === 'function') {

0 commit comments

Comments
 (0)