Skip to content

Commit 35f54a2

Browse files
Skip ensuring some indexes to be created when running against Azure Cosmos DB for MongoDB
Add docs change and config validator
1 parent 65e5879 commit 35f54a2

File tree

5 files changed

+49
-25
lines changed

5 files changed

+49
-25
lines changed

src/Config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class Config {
8585
allowExpiredAuthDataToken,
8686
logLevels,
8787
rateLimit,
88+
azureCosmosMongoDbCompatibleMode,
8889
databaseOptions,
8990
}) {
9091
if (masterKey === readOnlyMasterKey) {
@@ -120,6 +121,7 @@ export class Config {
120121
this.validateSchemaOptions(schema);
121122
this.validateEnforcePrivateUsers(enforcePrivateUsers);
122123
this.validateAllowExpiredAuthDataToken(allowExpiredAuthDataToken);
124+
this.validateAzureCosmosMongoDbCompatibleMode(azureCosmosMongoDbCompatibleMode);
123125
this.validateRequestKeywordDenylist(requestKeywordDenylist);
124126
this.validateRateLimit(rateLimit);
125127
this.validateLogLevels(logLevels);
@@ -166,6 +168,12 @@ export class Config {
166168
}
167169
}
168170

171+
static validateAzureCosmosMongoDbCompatibleMode(azureCosmosMongoDbCompatibleMode) {
172+
if (typeof azureCosmosMongoDbCompatibleMode !== 'boolean') {
173+
throw 'Parse Server option azureCosmosMongoDbCompatibleMode must be a boolean.';
174+
}
175+
}
176+
169177
static validateSecurityOptions(security) {
170178
if (Object.prototype.toString.call(security) !== '[object Object]') {
171179
throw 'Parse Server option security must be an object.';

src/Controllers/DatabaseController.js

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,30 +1706,33 @@ class DatabaseController {
17061706
throw error;
17071707
});
17081708

1709-
await this.adapter
1710-
.ensureIndex('_User', requiredUserFields, ['username'], 'case_insensitive_username', true)
1711-
.catch(error => {
1712-
logger.warn('Unable to create case insensitive username index: ', error);
1713-
throw error;
1714-
});
1715-
await this.adapter
1716-
.ensureIndex('_User', requiredUserFields, ['username'], 'case_insensitive_username', true)
1717-
.catch(error => {
1718-
logger.warn('Unable to create case insensitive username index: ', error);
1719-
throw error;
1720-
});
1721-
1709+
if (!this.options.azureCosmosMongoDbCompatibleMode) {
1710+
await this.adapter
1711+
.ensureIndex('_User', requiredUserFields, ['username'], 'case_insensitive_username', true)
1712+
.catch(error => {
1713+
logger.warn('Unable to create case insensitive username index: ', error);
1714+
throw error;
1715+
});
1716+
await this.adapter
1717+
.ensureIndex('_User', requiredUserFields, ['username'], 'case_insensitive_username', true)
1718+
.catch(error => {
1719+
logger.warn('Unable to create case insensitive username index: ', error);
1720+
throw error;
1721+
});
1722+
}
17221723
await this.adapter.ensureUniqueness('_User', requiredUserFields, ['email']).catch(error => {
17231724
logger.warn('Unable to ensure uniqueness for user email addresses: ', error);
17241725
throw error;
17251726
});
17261727

1727-
await this.adapter
1728-
.ensureIndex('_User', requiredUserFields, ['email'], 'case_insensitive_email', true)
1729-
.catch(error => {
1730-
logger.warn('Unable to create case insensitive email index: ', error);
1731-
throw error;
1732-
});
1728+
if (!this.options.azureCosmosMongoDbCompatibleMode) {
1729+
await this.adapter
1730+
.ensureIndex('_User', requiredUserFields, ['email'], 'case_insensitive_email', true)
1731+
.catch(error => {
1732+
logger.warn('Unable to create case insensitive email index: ', error);
1733+
throw error;
1734+
});
1735+
}
17331736

17341737
await this.adapter.ensureUniqueness('_Role', requiredRoleFields, ['name']).catch(error => {
17351738
logger.warn('Unable to ensure uniqueness for role name: ', error);
@@ -1755,12 +1758,14 @@ class DatabaseController {
17551758
options = this.idempotencyOptions;
17561759
options.setIdempotencyFunction = true;
17571760
}
1758-
await this.adapter
1759-
.ensureIndex('_Idempotency', requiredIdempotencyFields, ['expire'], 'ttl', false, options)
1760-
.catch(error => {
1761-
logger.warn('Unable to create TTL index for idempotency expire date: ', error);
1762-
throw error;
1763-
});
1761+
if (!this.options.azureCosmosMongoDbCompatibleMode) {
1762+
await this.adapter
1763+
.ensureIndex('_Idempotency', requiredIdempotencyFields, ['expire'], 'ttl', false, options)
1764+
.catch(error => {
1765+
logger.warn('Unable to create TTL index for idempotency expire date: ', error);
1766+
throw error;
1767+
});
1768+
}
17641769
}
17651770
await this.adapter.updateSchemaWithIndexes();
17661771
}

src/Options/Definitions.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ module.exports.ParseServerOptions = {
103103
'Configuration for your authentication providers, as stringified JSON. See http://docs.parseplatform.org/parse-server/guide/#oauth-and-3rd-party-authentication',
104104
action: parsers.arrayParser,
105105
},
106+
azureCosmosMongoDbCompatibleMode: {
107+
env: 'PARSE_SERVER_AZURE_COSMOS_MONGO_DB_COMPATIBLE_MODE',
108+
help:
109+
'Set to true for running against Azure Cosmos for Mongo DB. This can bring some performance loss.',
110+
action: parsers.booleanParser,
111+
default: false,
112+
},
106113
cacheAdapter: {
107114
env: 'PARSE_SERVER_CACHE_ADAPTER',
108115
help: 'Adapter module for the cache',

src/Options/docs.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Options/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ export interface ParseServerOptions {
300300
/* Options to limit repeated requests to Parse Server APIs. This can be used to protect sensitive endpoints such as `/requestPasswordReset` from brute-force attacks or Parse Server as a whole from denial-of-service (DoS) attacks.<br><br>ℹ️ Mind the following limitations:<br>- rate limits applied per IP address; this limits protection against distributed denial-of-service (DDoS) attacks where many requests are coming from various IP addresses<br>- if multiple Parse Server instances are behind a load balancer or ran in a cluster, each instance will calculate it's own request rates, independent from other instances; this limits the applicability of this feature when using a load balancer and another rate limiting solution that takes requests across all instances into account may be more suitable<br>- this feature provides basic protection against denial-of-service attacks, but a more sophisticated solution works earlier in the request flow and prevents a malicious requests to even reach a server instance; it's therefore recommended to implement a solution according to architecture and user case.
301301
:DEFAULT: [] */
302302
rateLimit: ?(RateLimitOptions[]);
303+
/* Set to true for running against Azure Cosmos for Mongo DB. This can bring some performance loss.
304+
:DEFAULT: false */
305+
azureCosmosMongoDbCompatibleMode: ?boolean;
303306
}
304307

305308
export interface RateLimitOptions {

0 commit comments

Comments
 (0)