'How to check if object is exist then update otherwise push a new object in to that using mongoose and node js express
Data added else is running perfectly I want my if statement solution.
const user = await Data.findOne({ email: req.body.email }).select("email").lean();
// here i want to update
if (user) {
console.log("data updated");
}
else {
const dataa = new Data(req.body)
let savedData = await dataa.save().then((resp) => console.log(resp))
console.log(savedData, "after save");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
