I'm working with Node.js and I'm using the Cloudant connector for the data source of loopback.
I have defined a model called User as defined below:
var User = db.define('User', {
lastName: { type: String },
firstName: { type: String },
skills: []
});
I have an instance of this model like:
{
"lastName": "Doe",
"firstName": "John",
"skills": [
{
"id": "0",
"text": "JAVA"
},
{
"id": "1",
"text": "CSS"
},
{
"id": "2",
"text": "HTML"
},
{
"id": 3,
"text": "JAVASCRIPT"
},
{
"id": 4,
"text": ".NET"
}
],
"id": "d981b42c3a2a13da382102c76652b96e"
}
I want to update the instance so that the skills array only contains this information:
"skills": [
{
"id": "0",
"text": "JAVAFX"
},
{
"id": "1",
"text": "CSS3"
}
]
I want to use this function:
app.post('/updateProfile', function(req, res) {
User.updateAll(
{_id:req.body.id},
{skills: req.body.skills},
function(err,items){
if(err){
res.send(err);
} else {
res.sendStatus(200);
}
});
});
However, the problem that I face is that only the skills with the same ID are updated. The ones that I want to be deleted (in the example it's HTML, JAVASCRIPT, and .NET) are NOT deleted.
How can I actually replace the skills instead of just doing an update? I've tried some other things that were described in the documentation, but it's not working. Documentation is available here