FG
🗄️ DatabasesMongoDB

Empty array is saved when a property references a schema

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

Problem

[code block] That will create an empty array of b.foos instead of just leaving the property undefined.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate2 verificationsLast verified Mar 14, 2026

Solution: Empty array is saved when a property references a schema

Low Risk

Ok, how do I make the default null? ;-) The usecase here is that it is expensive in mongo to request all of the Bar's that have empty foos. I have to add another property to track that state, which just complicates my code further.

84

Trust Score

2 verifications

100% success
  1. 1

    Ok, how do I make the default null? ;-) The usecase here is that it is expensive

    Ok, how do I make the default null? ;-) The usecase here is that it is expensive in mongo to request all of the Bar's that have empty foos. I have to add another property to track that state, which just complicates my code further.

Validation

Resolved in Automattic/mongoose GitHub issue #1335. Community reactions: 1 upvotes.

Verification Summary

Worked: 2
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

mongoosemongodbodmenhancement