我想在node.js应用程序内更新我的数据库,但它不工作。我console.log了参数,他们正确显示(即品牌,大小和用户电子邮件都是有效的和定义)。我如何完成这项工作?控制器内MongoDB没有在node.js应用程序中更新?
功能是被呼叫:
var User = require('../models/user');
exports.addToFavs = function(req, res) {
var user=req.user;
var brandToFind = req.body.brand;
var size_result = req.body.size;
var email_user = user.local.email;
//res.send? local.email?
User.update({local: {email: email_user}} , {$set: { $push: { favorite_shoes: { brand: brandToFind, size: size_result}}}} , {multi : true}, function(error) {
if (error) console.log(error);
console.log('Added %s with size=%s', brandToFind, size_result);
console.log(User.find(email_user));
res.redirect('/favorites');
})
};
模式:
var userSchema = mongoose.Schema({
local : {
email : String,
password : String,
},
favorite_shoes : [shoeSchema],
history: [searchSchema],
});
var shoeSchema = mongoose.Schema({
brand: String,
size: String,
});
var searchSchema = mongoose.Schema({
brand_original: String,
brand_result: String,
size: String,
});
我不使用猫鼬,但你shoeSchema和searchSchema应userSchema之前,因为'favorite_shoes:[shoeSchema]'是非常'favorite_shoes:[未定义]' – OneOfOne
我这样做,它仍然无法正常工作。 – girlrockingguna