mongodb-js / mongoose-autopopulate

Always populate() certain fields in your mongoose schemas
Apache License 2.0
222 stars 36 forks source link

Autopopulate Fails with Empty Array #86

Closed DiegoPerea closed 3 years ago

DiegoPerea commented 3 years ago

Hello

Autopopulate is failing when the autopopulated field is an empty array.

In my Project Schema the field "clients" doesn't always have values. Some projects have clients others don't.

When I try the mongoose function "findOneAndUpdte" it fails and the message is: (node:11503) UnhandledPromiseRejectionWarning: CastError: Cast to [ObjectId] failed for value "[""]" at path "clients"

Fails only on update. On Find it works OK.

DiegoPerea commented 3 years ago

Nevermind it was my error. It was a validation in mongoose.