简体   繁体   中英

Why mongoose.model() is required to get data from MongoDB?

I want to read data from the mongodb with mongoose , but every time it requires creating a model . Why? I thought model are just like templates to insert data to MongoDB. Can anyone describe what exactly mongoose.model() is and how it works?

I tried

const Model = mongoose.model(mongoose.Schima())

Without object in it And it worked as well!!!

How does mongoose.model get data in background?

Thank you...

Mongoose models are much more than just templates on how to store data in the database: they perform type conversion, provide validation, have pre/post hooks, provide easy methods for population, and much more.

You don't need to use a full model to retrieve data from the database (in fact, you don't even need Mongoose at all), but you'll lose all the additional features.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM