Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception value.map is not a function when array field is undefined in collection #38

Closed
vitorgamer58 opened this issue Aug 22, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@vitorgamer58
Copy link
Contributor

Describe the bug
When bringing an array field that is undefined in the database, the dataMapper returns an exception claiming that value.map is not a function.

To Reproduce
Search for a document from the database that contains a field declared in the entity as an array and that is undefined in the collection.

Expected behavior
The expected behavior is that the field is returned as undefined, since it does not exist in the database.

Additional context
This problem happens because when parsing an array, it is only checked if it is equal to null, but there is a difference in MongoDB between null and undefined, if I save a field as null, the key exists in the document, but with a null value, but if the key does not exist in the document, when the datamapper tries to parse the value (which will be undefined), the check will only be made if value is equal to null, after that it tries to call value.map, being value undefined, an exception is generated.

@vitorgamer58
Copy link
Contributor Author

Solved in commit 2453cb7 using checker.isEmpty.
This commit was included in version 4.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant