Insert data with mongoose; Then use mongodb shell to look at the inserted data and find it out

  node.js, question

The problem is as detailed as the topic.

clipboard.png

clipboard.png

It is recommended thatMongoose documentTo learn.
(or search mongoose’s related technology blog to learn how to use google well)

A brief answer:

Why define data types

One of mongodb’s major advantages is schemaless, that is, there is no need to preset the data structure. Why does mongoose define data types?
Mongodb’s schemaless has great advantages in today’s rapidly changing projects, while mongoose’s schema-based schema is not a retrogression, it is only for the convenience of development.
You can modify the schema at any time, but in most cases you do not need to organize the database and run it directly.
There is a schema that describes the data type. You can operate mongodb database more easily. (There are also advantages of oop)
Mongoose has built-in schema-based advantages like type conversion, default value, etc.

mongoose.model('Book', BookSchema)What is it

Register BookSchema with mBookgoose on the bookmodel.
So you can use it latermongoose.model('Book')Take this model out.
Mongoose has the concepts of schema, model and document.

Why?db.book.find({})No data found

Please usedb.books.find({})
Mongoose will make plural forms by itself, which is more professional. After all, it is a collection.
Besides, stories can also be plural to stories.
You are inuse blogAfter that, you can passshow collectionsKnow which collection exist.

Digression

It is suggested that the subject should study the document (blog tutorial) before asking questions.
Mongodb’s.