parse-community / parse-community/parse-server
`TypeError: type.startsWith is not a function` when starting Parse Server with custom schema data
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 21.4k
- Forks
- 4.8k
- Avg merge
- 7h 45m
- Merged PRs (30d)
- 11
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in MongoSchemaCollection.js at mongoFieldToParseSchemaField, then trace how mongoSchemaFieldsToParseSchemaFields handles malformed custom schema data. Confirm the expected Parse Server error behavior for undefined, null, and non-string type values, and verify startup no longer exposes a raw startsWith TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mongodb
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100