FG
🗄️ DatabasesMongoDB

Cast to number failed for value "undefined"

Freshover 10 years ago
Mar 14, 20260 views
Confidence Score87%
87%

Problem

Hi, with the latest version of mongoose, I have a mysterious problem. If I want to save document without specific typed field because it's not required, mongoose return this error in my face : [code block] This is my model schema. It works fine in 3.8.24 : [code block]

Error Output

Cast to number failed for value "undefined" at path "parent"
```

This is my model schema. It works fine in 3.8.24 :

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate1 verificationLast verified Mar 14, 2026

Solution: Cast to number failed for value "undefined"

Low Risk

I don't understand your problem, can't quite translate your prose into code. Can you provide a code example that reproduces the issue you're seeing?

84

Trust Score

1 verification

100% success
  1. 1

    I don't understand your problem, can't quite translate your prose into code. Can

    I don't understand your problem, can't quite translate your prose into code. Can you provide a code example that reproduces the issue you're seeing?

Validation

Resolved in Automattic/mongoose GitHub issue #2901. Community reactions: 0 upvotes.

Verification Summary

Worked: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

mongoosemongodbodm