parse-community / parse-community/parse-server

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

Open
#9,847 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:bug
Dominant language
JavaScript
Stars
21.4k
Forks
4.8k
Avg merge
7h 45m
Merged PRs (30d)
11

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.