node - 用mongoose 插入数据;然后用mongodb shell 查看插入的数据,查不出来
PHP中文网
PHP中文网 2017-05-02 09:19:57
0
1
563

问题详细如题;

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
Ty80

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:

Why do we need to define data types

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 for

Register 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.

Whydb.book.find({})can’t find data

Please use db.books.find({})db.books.find({})
mongoose会自己搞复数形式,显得比较专业,毕竟是collection嘛。
而且story还会复数成stories呢。
你在use blog之后,可以通过show collectionsmongoose can make plural forms by itself, which looks more professional. After all, it is a collection.

And story will also be pluralized into stories.

After use blog, you can know which collections exist through show collections.

Off topic

It is recommended that the questioner study the documentation (blog tutorial) before asking questions. 🎜mongodb, mongoose. 🎜
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!