不是所有mongoose schema上的数据都能贴出来
Not all the data on mongoose schema can be posted
我有一个 mongoose 架构如下:
var myprojectsSchema = new Schema({
pname: String,
pnumber: String,
plocation: String,
pclient: String,
clientabn: String,
contname: String,
contnumber: String,
mobile: String,
address: String,
city: String,
country: String,
pocode: String,
pdesc: String,
punit: String,
pqty: String,
prate: String,
pprice: String,
});
Myprojects = mongoose.model("Myprojects", myprojectsSchema);
当我 post 从表单中获取数据时,并不是所有的数据都可以在 mongo 数据库中看到,我只能在 mongo 数据库中看到前 12 个项目,但不能最后 5 个。请注意,我的表格上没有最后 5 个项目,但我仍然应该将它们视为数据上的 "nill",是否正确? (我有另一个模式完全相同的情况,但可以看到模式中的所有项目)
下面是 post 路线:
app.post("/myprojects", function(req,res){
var pname = req.body.pname;
var pnumber = req.body.pnumber;
var plocation = req.body.plocation;
var pclient = req.body.pclient;
var clientabn = req.body.clientabn;
var contname = req.body.contname;
var contnumber = req.body.contnumber;
var mobile = req.body.mobile;
var address = req.body.address;
var city = req.body.city;
var country = req.body.country;
var pocode = req.body.pocode;
var pdesc = req.body.pdesc;
var punit = req.body.punit;
var pqty= req.body.pqty;
var prate= req.body.prate;
var pprice= req.body.pprice;
var newProject = {
pname:pname,
pnumber:pnumber,
plocation:plocation,
pclient:pclient,
clientabn:clientabn,
contname:contname,
contnumber:contnumber,
mobile:mobile,
address:address,
city:city,
country:country,
pocode:pocode,
pdesc:pdesc,
punit:punit,
pqty:pqty,
prate:prate,
pprice:pprice,
};
Myprojects.create(newProject,function(err, newlycreated){
if(err){console.log(err);}else{
res.redirect("/myprojects");
}
});
});
如果 属性 没有可用值,则 属性 将被视为 undefined
。这就是为什么您在 mongodb 中看不到它的原因。
您可以使用默认值如下:
pprice: {
type: String,
default: null
}
我有一个 mongoose 架构如下:
var myprojectsSchema = new Schema({
pname: String,
pnumber: String,
plocation: String,
pclient: String,
clientabn: String,
contname: String,
contnumber: String,
mobile: String,
address: String,
city: String,
country: String,
pocode: String,
pdesc: String,
punit: String,
pqty: String,
prate: String,
pprice: String,
});
Myprojects = mongoose.model("Myprojects", myprojectsSchema);
当我 post 从表单中获取数据时,并不是所有的数据都可以在 mongo 数据库中看到,我只能在 mongo 数据库中看到前 12 个项目,但不能最后 5 个。请注意,我的表格上没有最后 5 个项目,但我仍然应该将它们视为数据上的 "nill",是否正确? (我有另一个模式完全相同的情况,但可以看到模式中的所有项目) 下面是 post 路线:
app.post("/myprojects", function(req,res){
var pname = req.body.pname;
var pnumber = req.body.pnumber;
var plocation = req.body.plocation;
var pclient = req.body.pclient;
var clientabn = req.body.clientabn;
var contname = req.body.contname;
var contnumber = req.body.contnumber;
var mobile = req.body.mobile;
var address = req.body.address;
var city = req.body.city;
var country = req.body.country;
var pocode = req.body.pocode;
var pdesc = req.body.pdesc;
var punit = req.body.punit;
var pqty= req.body.pqty;
var prate= req.body.prate;
var pprice= req.body.pprice;
var newProject = {
pname:pname,
pnumber:pnumber,
plocation:plocation,
pclient:pclient,
clientabn:clientabn,
contname:contname,
contnumber:contnumber,
mobile:mobile,
address:address,
city:city,
country:country,
pocode:pocode,
pdesc:pdesc,
punit:punit,
pqty:pqty,
prate:prate,
pprice:pprice,
};
Myprojects.create(newProject,function(err, newlycreated){
if(err){console.log(err);}else{
res.redirect("/myprojects");
}
});
});
如果 属性 没有可用值,则 属性 将被视为 undefined
。这就是为什么您在 mongodb 中看不到它的原因。
您可以使用默认值如下:
pprice: {
type: String,
default: null
}