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
Describe the bug
When an array is empty [] in the database, it is being converted to null when passed to the entity.
This bug was introduced in the commit 2453cb7
It has already been described in this comment (#37 (comment)) the reason why checker.isEmpty could not be used in this line. At least not returning null.
The reason why this bug ended up being implemented was due to an unhandled exception when the field was declared as an array but was undefined in the database, and when returning value.map((i) => parser(i)) ends generating an exception, as described in this issue: Exception value.map is not a function when array field is undefined in collection
Therefore, there is a need to use either checker.isEmpty or if (value == undefined || value == null).
The checker would be the most appropriate, because, being undefined, null or empty array, the value itself is returned without carrying out any additional processing.
The correction is very important because it is a breaking change implemented in version 4.0.1 of Herbs2Mongo.
To Reproduce
Save an object to the database whose entity has an array field, with that field being an empty array.
When searching for this object, instead of an empty array, it will return null.
Expected behavior
As a complement to the issue #39, it should return the value that is in the database if it is null, undefined if the key does not exist in the database, and empty array if it is like this in the database.
The MongoDB library and database handle whether a value will be null or undefined during a database search. The necessary adjustment is in how this value is converted to an entity.
The text was updated successfully, but these errors were encountered:
Describe the bug
When an array is empty
[]
in the database, it is being converted tonull
when passed to the entity.This bug was introduced in the commit 2453cb7
It has already been described in this comment (#37 (comment)) the reason why
checker.isEmpty
could not be used in this line. At least not returning null.The reason why this bug ended up being implemented was due to an unhandled exception when the field was declared as an array but was undefined in the database, and when returning
value.map((i) => parser(i))
ends generating an exception, as described in this issue: Exception value.map is not a function when array field is undefined in collectionTherefore, there is a need to use either
checker.isEmpty
orif (value == undefined || value == null)
.The checker would be the most appropriate, because, being undefined, null or empty array, the value itself is returned without carrying out any additional processing.
The correction is very important because it is a breaking change implemented in version 4.0.1 of Herbs2Mongo.
To Reproduce
Save an object to the database whose entity has an array field, with that field being an empty array.
When searching for this object, instead of an empty array, it will return null.
Expected behavior
As a complement to the issue #39, it should return the value that is in the database if it is null, undefined if the key does not exist in the database, and empty array if it is like this in the database.
The MongoDB library and database handle whether a value will be null or undefined during a database search. The necessary adjustment is in how this value is converted to an entity.
The text was updated successfully, but these errors were encountered: