mongodb - Why does Mongoose automatically add s and lowercase when creating a collection?
过去多啦不再A梦
过去多啦不再A梦 2017-05-31 10:35:36
0
2
828

I didn’t find the relevant explanation in the document, please give me some advice, thank you.

Mongoose uses the model to create the corresponding collection in mongodb. When mongoose creates the collection internally, it lowercases the collection name ('friendimpression') we pass. At the same time, if there are no letters after the lowercase name—— s, then an s will be added after it. For the collection we just created, it will be named: friendimpressions.

过去多啦不再A梦
过去多啦不再A梦

reply all(2)
伊谢尔伦

1. Found from the document:

The first argument is the singular name of the collection your model is for. Mongoose automatically looks for the plural version of your model name. Thus, for the example above, the model Tank is for the tanks collection in the database. The . model() function makes a copy of schema. Make sure that you've added everything you want to schema before calling .model()!

2. You can specify the name of the collection in the third parameter.

For reference!

Love MongoDB! Have fun!


The 2017 MongoDB Chinese Community Beijing User Group Conference is coming soon, June 3, 2017 13:00-18:00

Registration now! Please click on the left!

巴扎黑

Here is a code example, you can see if it helps https://github.com/treeandgra...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template