Skip to content

Commit 8d90d30

Browse files
committed
fix(MongoSchemaCollection): prevent TypeError when type is not a string
Added a type check in mongoFieldToParseSchemaField to ensure `type` is a string before calling `startsWith`. This prevents crashes when Parse Server processes MongoDB schema fields with undefined, null, or unexpected type values. Closes #9847
1 parent 4b3f10b commit 8d90d30

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Adapters/Storage/Mongo/MongoSchemaCollection.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import MongoCollection from './MongoCollection';
22
import Parse from 'parse/node';
33

44
function mongoFieldToParseSchemaField(type) {
5+
// Add type validation to prevent TypeError
6+
if (!type || typeof type !== 'string') {
7+
throw new Parse.Error(
8+
Parse.Error.INVALID_SCHEMA_OPERATION,
9+
`Invalid field type: ${type}. Expected a string. Field type must be one of: string, number, boolean, date, map, object, array, geopoint, file, bytes, polygon, or a valid relation/pointer format.`
10+
);
11+
}
12+
513
if (type[0] === '*') {
614
return {
715
type: 'Pointer',

0 commit comments

Comments
 (0)