jedireza / mongo-models

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

Using dynamic schema #34

Closed anhntbk08 closed 5 years ago

anhntbk08 commented 5 years ago

Hi there,

Thank for your great lib, one question here is how can i use dynamic schema? I want to use some important fields for indexing and set the constrain for the data otherwise i want to use remain as dynamic fields? Is that possible?

Thanks.

jedireza commented 5 years ago

Maybe something like:

const schema = Joi.object({
    _id: Joi.object(),
    name: Joi.string().required(),
    dynamic: Joi.object()
});
anhntbk08 commented 5 years ago

@jedireza this is not what i need, i need something like {strict: false} in mongoose? Any other idea ?

jedireza commented 5 years ago

Nope. Probably just use mongoose.

anhntbk08 commented 5 years ago

i should use Joi to validate the schema instead of using mongo-models does that

Thanks for your support