2015-09-11 23 views
1

我有風帆js 0.11v和mongodb,當我使用sails js的.update函數,除enum attrribute每隔其他值更新。並非所有的模型值更新使用.update()方法

這裏是我的模型

module.exports = { 
    schema: true, 
    attributes: { 
     name: { 
      type: 'string', 
      required: true 
     }, 
     type: { 
      type: 'string', 
      required: true, 
      enum: ['open', 'user'] 
     }, 

     state: { 
      type: 'integer', 
      enum: [0, 1, 2, 3, 4, 5, 6], 
      defaultsTo: 0 

     } 

    } 

}; 

下面的代碼是負責更新值

Challenge.update({ 
    id: '55e81f5998e63e7c1ebe4ab6' 
}, { 
    state: 2 
}, { 
    type: 'user' 
}).exec(function afterwards(err, updated) { 
    if (err) { 
     return res.json(err); 
    } else { 
     return res.json(updated); 
    } 
}); 

,但它不以挑戰更新類型和狀態參數。它導致舊數據

+3

當每個字段需要全部位於同一對象中時,您正在使用單獨的對象。這就是它失敗的原因。即「{」state「:2,」type「:」user「}' –

+1

Umm。這是因爲「第一個」文檔是查詢,而「第二個」是更新。你只是想要「兩個」。你有「三」。使用我所說的「第二」。 –

+0

感謝幫助,它解決了我的問題 – rash111

回答

0

其實我有同樣的問題在幾分鐘前,這個問題是.update()只接受2 PARAMS,所以你可以按照下面編輯:

Challenge.update( {ID: '55e81f5998e63e7c1ebe4ab6'}{狀態:2,類型: '用戶'}).exec(函數之後(ERR,更新){ 如果(ERR){ 返回res.json(ERR); } else { return res.json(updated); } });

它的工作原理!

相關問題