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);
}
});
,但它不以挑戰更新類型和狀態參數。它導致舊數據
當每個字段需要全部位於同一對象中時,您正在使用單獨的對象。這就是它失敗的原因。即「{」state「:2,」type「:」user「}' –
Umm。這是因爲「第一個」文檔是查詢,而「第二個」是更新。你只是想要「兩個」。你有「三」。使用我所說的「第二」。 –
感謝幫助,它解決了我的問題 – rash111