mongodb - 为什么Mongoose在创建collection的时候会自动添加s和小写?

查看:305
本文介绍了mongodb - 为什么Mongoose在创建collection的时候会自动添加s和小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

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

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

解决方案

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

报名中!请戳左边!

这篇关于mongodb - 为什么Mongoose在创建collection的时候会自动添加s和小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆