为什么猫鼬总是在我的收藏名称末尾添加一个 s [英] Why does mongoose always add an s to the end of my collection name

查看:29
本文介绍了为什么猫鼬总是在我的收藏名称末尾添加一个 s的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,此代码导致创建名为datas"的集合

For example, this code results in a collection called "datas" being created

var Dataset = mongoose.model('data', dataSchema);

此代码导致创建一个名为users"的集合

And this code results in a collection called "users" being created

var User = mongoose.model('user', dataSchema);

谢谢

推荐答案

Mongoose 试图通过使您的集合名称复数来变得聪明.但是,您可以强制它成为您想要的任何内容:

Mongoose is trying to be smart by making your collection name plural. You can however force it to be whatever you want:

var dataSchema = new Schema({..}, { collection: 'data' })

这篇关于为什么猫鼬总是在我的收藏名称末尾添加一个 s的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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