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

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

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

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

全部回复(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...

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!