-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Description
New Issue Checklist
- Report security issues confidentially.
- Any contribution is under this license.
- Before posting search existing issues.
Issue Description
When starting Parse Server with custom schema data, the server fails to start with the error:
TypeError: type.startsWith is not a function
The error originates from MongoSchemaCollection.js
, specifically in the mongoFieldToParseSchemaField
function.
Steps to reproduce
- Start Parse Server with custom MongoDB schema data(with incompatible data).
- Server crashes during initialization with the above error.
Actual Outcome
Parse Server crashes on startup with:
TypeError: type.startsWith is not a function
at mongoFieldToParseSchemaField (C:\Users\mypre\projects\parse-server-exp\node_modules\parse-server\lib\Adapters\Storage\Mongo\MongoSchemaCollection.js:25:12)
at mongoSchemaFieldsToParseSchemaFields (C:\Users\mypre\projects\parse-server-exp\node_modules\parse-server\lib\Adapters\Storage\Mongo\MongoSchemaCollection.js:78:29)
at mongoSchemaToParseSchema (C:\Users\mypre\projects\parse-server-exp\node_modules\parse-server\lib\Adapters\Storage\Mongo\MongoSchemaCollection.js:148:13)
Expected Outcome
Parse Server should handle unexpected or malformed schema type
values gracefully instead of crashing.
Root Cause
The code calls type.startsWith('relation<')
without ensuring that type
is a string.
If type
is undefined
, null
, or any non-string, startsWith
is not available, causing a crash.
Problematic Code
// In MongoSchemaCollection.js
if (type.startsWith('relation<')) {
return {
type: 'Relation',
targetClass: type.slice('relation<'.length, type.length - 1)
};
}
Suggested Fix
if (!type || typeof type !== 'string') {
throw new Parse.Error(...); // Ensure type is a string before calling startsWith
}
Environment
Server
Parse Server version: 6.2.0
Operating system: Windows 11
Local or remote host: Local
Database
System: MongoDB
Database version: 7.0
Local or remote host: Local
Logs
(see error stack trace above)