2013-01-11 36 views
0

我想更新一個文檔(在模型ID 1上放置用戶名'toto')。問題是,update()調用會發生任何事情(就像應用程序正在等待某些事情一樣),並且我不會去更新回調。試圖更新文檔

我不明白髮生了什麼,這裏是代碼:

UserSchema : { 
    username: { 
     type: String, 
     required: true, 
     unique: true 
    }, 
}; 

var UserSchema = new mongoose.Schema(UserSchema); 
UserSchema 
     .virtual('id') 
     .get(function(){ 
      return this.get('_id'); 
     }).set(function(id){ 
      return this.set('_id', id); 
     });  

var User = db.model('User', UserSchema); 
var Entity = new User(); 

Entity.update({ _id: 1 }, { username: 'toto'}, null, function(error, numAffected){ 
    if (error){ 
     console.log("|-->Error Query trying to update model"); 
    }else{ 
     console.log("|-->Update model succeed"); 
    } 
}); 

謝謝!

回答

0

我的問題是在其實例上使用Use和update(),而不是將update()調用應用於UserSchema。