mongodb-js / mongoose-autopopulate

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

How to disable auto populate when create. #100

Closed ZhaoKunLong closed 1 year ago

ZhaoKunLong commented 2 years ago

How to disable auto populate when create.

Is any one know how to resolve it?

vkarpov15 commented 1 year ago

Try await this.model.create([fields], { autopopulate: false }); . In Mongoose, Model.create(o1, o2) creates 2 objects o1, o2. If you want to pass options to create, you should pass array as first param. See the Model.create docs

ZhaoKunLong commented 1 year ago

Oh!! @vkarpov15 Nice thanks for your reply! It really helped!