Hey there community
I am having trouble with the deleteMany of ids.
Namely, I am passing via api call an array of string [“6507706269daaddf53f7a722”, “6507707069daaddf53f7a723”]
Then, I am handling the api call like so:
else if (request.method === 'DELETE') {
const idsToDelete = request.body.selected.map((_id: any) => new ObjectId(_id))
console.log(idsToDelete);
//[
//new ObjectId("6507706269daaddf53f7a722"),
//new ObjectId("6507707069daaddf53f7a723")
//]
await dbProducts.deleteMany({ _id: { in: idsToDelete } }).catch((error) => console.log(error))
return response.status(200).json({ message: 'Product successfully deleted!' });
}
I get the OK status of the responce, but the ids are not deleted.
I have also tried to create the array for the “in” like so:
const idsToDelete = request.body.selected.map((_id: any) => ObjectId("${_id}")
)
but to no avail
Can anyone help?
anyone