parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

`TypeError: type.startsWith is not a function` when starting Parse Server with custom schema data

Open rgunindi opened this issue 3 months ago • 1 comments

New Issue Checklist

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

  1. Start Parse Server with custom MongoDB schema data(with incompatible data).
  2. 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)

rgunindi avatar Aug 24 '25 14:08 rgunindi

🚀 Thanks for opening this issue!

ℹ️ You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.