I have sails js 0.11v and mongodb, when i use .update function of sails js, Except enum attrribute every other value is updating.
Here is my model
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
}
}
};
Below code is responsible for updating values
Challenge.update({
id: '55e81f5998e63e7c1ebe4ab6'
}, {
state: 2
}, {
type: 'user'
}).exec(function afterwards(err, updated) {
if (err) {
return res.json(err);
} else {
return res.json(updated);
}
});
but it dont update type and state parameter in challenge. It results old data
Actually i had the same issue a couple of minutes ago, the problem is that .update() accepts only 2 params, so you could edit according to the following:
Challenge.update({id:'55e81f5998e63e7c1ebe4ab6'}, {state: 2,type: 'user'}).exec(function afterwards(err, updated) { if (err) { return res.json(err); } else { return res.json(updated); } });
And it works!