mongodb - 为什么Mongoose在创建collection的时候会自动添加s和小写?
过去多啦不再A梦
过去多啦不再A梦 2017-05-31 10:35:36
0
2
717

我没有在文档里找到相关的解释,求指点,谢谢.

mongoose是通过model来创建mongodb中对应的collection的,mongoose在内部创建collection时将我们传递的collection名(‘friendimpression’)小写化,同时如果小写化的名称后面没有字母——s,则会在其后面添加一s,针对我们刚建的collection,则会命名为:friendimpressions。

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

répondre à tous(2)
伊谢尔伦

1、从文档中找到:

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、可以自己在第三个参数指定collection的名字。

供参考!

Love MongoDB! Have fun!


2017MongoDB中文社区北京用户组大会在即,2017年6月3日 13:00-18:00

报名中!请戳左边!

巴扎黑

这有代码的例子,可以看哈是否有帮助https://github.com/treeandgra...

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!