PHP中文网2017-05-02 09:21:57
It is recommended to study according to the mongoose documentation.
(Or search mongoose related technology blogs and learn to use google)
Let me give you a brief answer:
A major advantage of mongodb is that it is schemaless, that is, there is no need to preset data structures. And why does mongoose need to define data types?
Mongodb's schemaless has great advantages in today's projects with rapidly changing requirements, and mongoose's schema-based model is not a step back, it is just for the convenience of development.
You can modify the schema at any time, and in most cases you can run it directly without reorganizing the database.
With a schema that describes data types, you can operate the mongodb database more easily. (Also including the advantages of oop)
mongoose has built-in schema-based advantageous functions such as type conversion, default value, etc.
mongoose.model('Book', BookSchema)
What is it forRegister BookSchema with mongoose on the Book model.
So you can use mongoose.model('Book')
to take out this model later.
mongoose has the concepts of schema, model, and document.
db.book.find({})
can’t find dataPlease use db.books.find({})
db.books.find({})
mongoose会自己搞复数形式,显得比较专业,毕竟是collection嘛。
而且story还会复数成stories呢。
你在use blog
之后,可以通过show collections
mongoose can make plural forms by itself, which looks more professional. After all, it is a collection.
use blog
, you can know which collections exist through show collections
. Off topic