You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the bug has not already been reported
Mongoose version
8.2.4
Node.js version
20.12.0
MongoDB server version
6.0.2 Community
Typescript version (if applicable)
5.4.3
Description
I have a schema which accepts an Object property.
On mongoose version 8+, when updating the document in DB, with an empty object ( {} ), the value that is actually being saved is null.
when querying the DB and fetching the relevant document, variables: null is being returned, which makes other validations in the system to throw the following error:
On older versions (tested on 7.6.3), it doesn't happen and it behave as expected (the object is being saved as an empty object):
I can ofc changing the validators in the system, but it seems like the wrong solution. empty object doesn't equal to null.
Steps to Reproduce
create a mongoose model with an object field. for example:
Prerequisites
Mongoose version
8.2.4
Node.js version
20.12.0
MongoDB server version
6.0.2 Community
Typescript version (if applicable)
5.4.3
Description
I have a schema which accepts an Object property.
On mongoose version 8+, when updating the document in DB, with an empty object (
{}
), the value that is actually being saved isnull
.when querying the DB and fetching the relevant document,
variables: null
is being returned, which makes other validations in the system to throw the following error:On older versions (tested on 7.6.3), it doesn't happen and it behave as expected (the object is being saved as an empty object):
I can ofc changing the validators in the system, but it seems like the wrong solution. empty object doesn't equal to null.
Steps to Reproduce
data: {}
). (the object will be saved withoutdata
property - which is fine)findOne
.data
field again to empty object:document.data = {}
document.save()
Expected Behavior
after update, the
data
field should be an empty object{}
. as can see using mongoDB Compass in old mongoose versions:another good solution for me, is if you will add a new parameter that will allow me to choose the way it should behave. (
allowNullable: false
)The text was updated successfully, but these errors were encountered: