我是这个 node 的新手.js、mongoose 和Expressjs.我试图通过以下代码使用MongoDB中的Mongoose创建一个表"feedbackdata".但它被创建为"反馈数据*s*".通过谷歌搜索,我发现mongoose 使用多元化规则.有人能帮我取消多元化规则吗?或者"反馈数据"表的代码应该是什么?

下面是我的代码:

app.post("/save",function(req,res){

mongoose.connect('mongodb://localhost/profiledb');

mongoose.connection.on("open", function(){
    console.log("mongo connected \n");
});

// defining schemar variables
Schema = mongoose.Schema,   
ObjectId = Schema.ObjectId;

// define schema for the feedbackdata table
var feedback_schema = new Schema({
    _id: String,
    url:String,
    username:String,
    email:String,
    subscribe:String,
    types:String,
    created_date: { type: Date, default: Date.now },
    comments: String
});

// accessing feeback model object
var feedback_table = mongoose.model('feedbackdata', feedback_schema);
var tableObj = new feedback_table();

var URL = req.param('url');
var name = req.param('name');
var email = req.param('email');
var subscribe = req.param('subscribe');
var choices = req.param('choices');
var html = req.param('html');
var receipt = req.param('receipt');    
var feedbackcontent = req.param('feedbackcontent');

tableObj._id = 3;
tableObj.url = URL;
tableObj.username = name;
tableObj.email = email;
tableObj.subscribe = subscribe;
tableObj.types = choices;
tableObj.comments = feedbackcontent;

tableObj.save(function (err){
    if(err) { throw err; }else{ 
        console.log("Saved!");              
    }
    mongoose.disconnect();
})

res.write("<div style='text-align:center;color:green;font-weight:bold;'>The above values saved successfully! <br><a href='/start'>Go back to feedback form</a></div>");     

res.end();

});

推荐答案

多元化规则在这个文件中:https://github.com/LearnBoost/mongoose/blob/master/lib/utils.js

您可以将您的模式名称添加到"不可数"列表中,这样mongoose就不会对您的模式名称进行复数.

Mongodb相关问答推荐

如何在MongoDB中对两个数组进行分组?

Select 筛选聚合中的嵌套字段

聚合管道可以用于更新数据库中的文档吗?

MongoDb聚合查询问题

Golang 无法在 MongoDB 中创建文档

如何使用指南针连接到 mongodb replicaset (k8s)

有没有一种方法可以找到一个文档并通过 Go 更改 mongodb 中的 id/value 来克隆它

MongoDB乘以对象值?

使用新字段插入数据或使用 updateOne mongodb 有条件地更新

从嵌套数组中 id 匹配的另一个集合中获取所有字段

Mongoose $inc 枚举验证失败

mongodb:多键索引 struct ?

MongoDB 列表 - 获取每第 N 个元素

mongod 和 mongo 命令在 Windows 10 上不起作用

使用 mongoimport 将日期(ISODate)导入 MongoDB

使用 MongoDB 进行嵌套分组

单个模式数组中的多个模式引用 - mongoose

使用 mongoengine 将多文档插入到 mongodb

AsQueryable 方法是否在新的 Mongodb C# 驱动程序 2.0rc 中离开?

对象不是 JSON 可序列化的