I have the following code in my node.js application where I either update a field or insert a new entry:
DocPrivilege.update({
_id: {
$in: user.documentsPriv
}
}, {
$set: {
access: parseInt(req.body.access),
documentName: req.body.documentName,
documentId: req.body.documentId
}
}, {
upsert: true
}, function(err, updated) {
if (err || !updated) console.log("User not updated");
else {
console.log("User updated");
}
});
Is there a way how I can differentiate if an update or an insertion occured?