有没有一种方法可以防止MongoDB向集合名称添加复数形式? [英] Is there a way to prevent MongoDB adding plural form to collection names?

查看:229
本文介绍了有没有一种方法可以防止MongoDB向集合名称添加复数形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我要创建一个名为"Mice"的集合之前,一切都很好. Mouses和Mices都不可接受.如果可以在配置中设置此选项,那就太好了. 评论:感谢您的建议,我正在使用猫鼬.

It all works fine until I want to create a collection named 'Mice' for example. Both Mouses and Mices are unacceptable. Would be good if there is an option to set this in the config. Comments: thanks for the suggestion, I am using Mongoose.

推荐答案

如果您将模型命名为"mouse",猫鼬实际上会将集合名称正确地复数为"mice"(请参见

If you name your model 'mouse', Mongoose will actually pluralize the collection name correctly to 'mice' (see source code).

但是在创建模型时,您也可以通过将其作为第三个参数传递给 model :

But you can also explicitly name your collection when creating a model by passing it as the third parameter to model:

var Mice = mongoose.model('Mice', MouseSchema, 'Mice');

这篇关于有没有一种方法可以防止MongoDB向集合名称添加复数形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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