mongoosejs / mongoose-lean-virtuals

Attach virtuals to the results of mongoose lean() queries
Apache License 2.0
45 stars 24 forks source link

Discriminators don't work if query result is an array #36

Closed FERNman closed 2 years ago

FERNman commented 4 years ago

Hi there,

Thanks for the plugin. I just noticed that virtuals in discriminators don't work if the result of a query is an array.

The problem is how you check which discriminator schema to apply on line 43 - 51. In attachVirtuals, res can be an array, and each of the documents can have a different schema. This method, however, only works for single documents.

I will submit a PR for this, including unit tests.