jedireza / mongo-models

:package: Map JavaScript classes to MongoDB collections
MIT License
67 stars 28 forks source link

[Question] Models schema validation breaks partial fields loading #38

Closed nosuchip closed 5 years ago

nosuchip commented 5 years ago

For instance, I have schema of Device where field passcode is Joi.string.require(). Now I want to get objects from corresponding collection but do not need all the fields. Let's say I want only get _id, name, lastSeen. So I am calling it like:

await Device.find(someQuery, Device.fieldAdapter('_id name lastSeen'))

This call throws an exception with Joi validation message child "passcode" fails because ["passcode" is required].

Looks like bug for me.

jedireza commented 5 years ago

Yep, that all makes sense. I'm not sure this is considered a bug though. It's not possible to fulfill all those requirements and have schema validation.