Почему вы пропускаете {name: "Yoda}
? Этот маршрут должен обновлять только цитату с "Йода" в качестве имени? Если нет, то вам нужно получить из объекта запроса цитату, которая должна быть обновлена.
Я попытался создать другую версию, исходя из предположения, что цитата, которая должна быть обновлена, будет получена из req. тело:
app.put("/quotes", async (req, res) => {
//Grab the name/id/identifier for the quote you want to update from the body
const query = req.body.name;
// Try to update the document on the database
try {
const result = await quoteCollection.findOneAndUpdate(
query,
{
name: req.body.name,
quote: req.body.quote,
},
{
upsert: true,
new: true,
}
);
// If it worked, it will return the updated quote
res.status(200).json({
status: 200,
data: {
result,
},
});
} catch (err) {
res.status(400).json({
status: 400,
message: "Something went wrong",
});
}
});