I'm getting (throw new error_1.MongoInvalidArgumentError('Update document requires atomic operators'); )
this type of error
Here is the full code for put endpoint:
app.put('/todo/:id', async (req, res) =>
{
const id = req.params.id; const data = req.body;
console.log(data);
const filter = { _id: ObjectId(id) };
const options = { upsert: true };
const updateDoc = { $set: { name: data.name, message: data.message, }, };
const result = await dataCollections.updateOne(filter, options, updateDoc);
res.send(result);
});
CodePudding user response:
You are sending the parameters in the wrong order, update document comes before options, try this:
const result = await dataCollections.updateOne(filter, updateDoc, options);