Mongoose模型没有方法" save"使用Passport.js

时间:2014-05-22 20:05:13

标签: post mongoose passport.js

在我的应用程序中,用户进行身份验证然后进行测验。我想将测验结果保存到用户架构。当我运行以下操作时,正确的信息将打印到控制台,但保存会给出错误:

//Error printing to console:
User.save(function(err){             ^
TypeError: Object function model(doc, fields, skipId) {
if (!(this instanceof model))
  return new model(doc, fields, skipId);
Model.call(this, doc, fields, skipId);
} has no method 'save'

//update the user with the kitten Type
app.post('/api/kittens', isLoggedIn, function (req, res, done) {

    console.log(req.user.kittenType); //an empty set by default
    console.log(req.body.kittenType); //the quiz result 


   User.findOne({ 'kittenType': req.user.kittenType}, function(err, user) {
    if(err) 
        return done(err);

    if(user) {
        User.kittenType = req.body.kittenType;
        User.save(function(err){
            if(!err){
                console.log('yay');
            }
            else {
                console.log(err);
            }
        });
        console.log(User.kittenType);
    }
}); 
});

var userSchema = mongoose.Schema({

    user            : {
        type: mongoose.Schema.ObjectId,
        ref: 'User'
    },

     kittenType   : String,
     local            : {
        email        : String,
        password     : String,
        petname      : String,
        path         : String,  
},


});

1 个答案:

答案 0 :(得分:0)

问题是大写:

应该是“user.kittenType”和“user.save”而不是“User.save”