-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Labels
backwards-breakingenhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new featureThis issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Milestone
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
7.4.4
Node.js version
16.20.2
MongoDB server version
7.0.0
Typescript version (if applicable)
No response
Description
Empty objects are sometimes deleted, sometimes not.
Steps to Reproduce
mongoose.connect("mongodb://127.0.0.1:27017/test");
const schema = new Schema({
metadata: {
type: {},
default: {},
required: true,
_id: false
}
}, { minimize: true });
const Model = model("Schema", schema);
const m = new Model({ metadata: {} });
await m.save();
console.log("Document has no metadata property")
const x = await Model.findById(m._id).exec();
x.metadata = {};
await x.save();
console.log(x.$isEmpty('metadata')) // true
console.log("Document now has empty metadata property");Expected Behavior
The saved document has the form
{
"_id": {
"$oid": "64e87a78972e351e7096f778"
},
"__v": 0
}but it is
{
"_id": {
"$oid": "64e87a78972e351e7096f773"
},
"__v": 0,
"metadata": {}
}Metadata
Metadata
Assignees
Labels
backwards-breakingenhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new featureThis issue is a user-facing general improvement that doesn't fix a bug or add a new feature