什么是猫鼬(Nodejs)复数规则? [英] What are Mongoose (Nodejs) pluralization rules?
问题描述
我是Node.js,Mongoose和Expressjs的新手.我试图通过以下代码在MongoDB中使用Mongoose创建一个表"feedbackdata".但是它被创建为"feedbackdata * s *".通过Googling,我发现猫鼬使用了复数规则.任何人都可以帮助我删除复数规则吗?或"feedbackdata"表的代码应如何?
I am a newbie to the Node.js, Mongoose and Expressjs. I have tried to create a table "feedbackdata" using the Mongoose in MongoDB via the following code. But it is created as "feedbackdata*s*". By Googling, I found that the Mongoose uses pluralization rules. Anyone please help me to remove the pluralization rules? or how my code should be for the "feedbackdata" table?
下面是我的代码:
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();
});
推荐答案
The pluralization rules are in this file: https://github.com/LearnBoost/mongoose/blob/master/lib/utils.js
您可以将架构名称添加到不可数"列表中,然后猫鼬不会使您的架构名称复数.
You can add your schema name to the 'uncountables' list, then mongoose will not pluralize your schema name.
这篇关于什么是猫鼬(Nodejs)复数规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!