Thank you for the answer, i am trying to do it like this:
const updateDoc = {
$set: {
health: 150,
attack: 3,
defence: 3,
endurance: 10,
characterimg: "https://i.ibb.co/MPg2SMp/Apocaliptic1.png",
},
$set: { $add : [ "$power", "$attack" ,"$defence" , { $devide : ["$endurance", 3]}]}
}
const result = await collection.updateOne(filter, updateDoc, options);
console.log(
`${result.matchedCount} document(s) matched the filter, updated ${result.modifiedCount} document(s)`,
);
} finally {
localStorage.firstTime = "No"
res.redirect('/main');
await client.close();
}
}
run().catch(console.dir);
})
But it gives me this error:
MongoError: The dollar ($) prefixed field ‘$add’ in ‘$add’ is not valid for storage.