Mongodb集合名称 [英] Mongodb Collection name

查看:111
本文介绍了Mongodb集合名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用mongoose在MongoDB中创建了一个数据库.尽管一切正常,但是当我检查mongodb时,集合的名称中带有额外的"s".创建的集合名称是雇员.可能出什么问题了,还是仅仅是猫鼬的命名约定?

I've created a database in MongoDB using mongoose. Although everything works fine, but when I check mongodb the name of the collection has extra 's' in its name. The collection name created is employees. What could be wrong, or is it just the naming convention of mongoose?

const mongoose = require('mongoose');

let employeeSchema = mongoose.Schema({
  name: String,
  email: String,
  department: String,
  doj: Date,
  address: String
});

const Employee = mongoose.model("employee", employeeSchema);

module.exports = Employee;

推荐答案

因此,您有两个选择来控制猫鼬中的文档名称.

So you have two options for controlling document names in mongoose.

如果您只想禁用复数形式,则可以按照Ankit的答案使用mongoose.pluralize(null)来实现.

If you just want to disable pluralization, you can do it with mongoose.pluralize(null) as in Ankit's answer.

如果您想更改集合名称,可以执行以下操作:

And if you want to change your collection name whatever you want, you can do:

mongoose.model("employee", employeeSchema, { collection: 'myEmployee' } ) 

这篇关于Mongodb集合名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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