我是Node.js,Mongoose和Expressjs的新手。我试图通过以下代码在MongoDB中使用Mongoose创建一个表“ feedbackdata”。但是它被创建为“ feedbackdata * s *”。通过谷歌搜索,我发现猫鼬使用了复数规则。任何人都可以帮助我删除复数规则吗?或“ feedbackdata”表的代码应如何?
下面是我的代码:
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
您可以将架构名称添加到“不可数”列表中,然后猫鼬不会使您的架构名称复数。