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

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

问题描述

一切正常,直到我想创建一个名为老鼠"的集合.老鼠和老鼠都是不可接受的.如果有一个选项可以在配置中设置它会很好.评论:感谢您的建议,我正在使用猫鼬.

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",Mongoose 实际上会将集合名称正确复数为mice"(请参阅​​ 源代码).

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

但是您也可以在创建模型时通过将其作为第三个参数传递给 来明确命名您的集合模型:

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天全站免登陆