mongoose queries error when processing a record which contains null as a value of an Array schema type.
TypeError: Cannot read properties of null (reading 'map')
at /mongoose-test/node_modules/mongoose-lean-getters/index.js:130:67
at Schema.eachPath (/mongoose-test/node_modules/mongoose/lib/schema.js:1569:5)
at model.Query.applyGettersToDoc (/mongoose-test/node_modules/mongoose-lean-getters/index.js:110:16)
at model.Query.applyGetters (/mongoose-test/node_modules/mongoose-lean-getters/index.js:51:25)
at model.Query.<anonymous> (/mongoose-test/node_modules/mongoose-lean-getters/index.js:36:18)
at next (/mongoose-test/node_modules/kareem/index.js:268:35)
at Kareem.execPost (/mongoose-test/node_modules/kareem/index.js:296:3)
at /mongoose-test/node_modules/mongoose/lib/query.js:4380:28
at new Promise (<anonymous>)
at _executePostHooks (/mongoose-test/node_modules/mongoose/lib/query.js:4377:10)
With this change we check for non-null after running possible array getters, but before running the for-each-element .map(). If the value is indeed null, we'll bail out of processing array elements, instead just continuing with the non-array codepath.
Summary
mongoose queries error when processing a record which contains null as a value of an Array schema type.
With this change we check for non-null after running possible array getters, but before running the for-each-element .map(). If the value is indeed null, we'll bail out of processing array elements, instead just continuing with the non-array codepath.
Fixes #35.