Estoy tratando de eliminar un objeto de un subarreglo sin suerte al obtener updateOne() no es una función y remove() no es una función.
Quiero eliminar el 'subcat 1' con id de '61cae5daf5bfbebd7cf748ef' :
[ { _id: '61cae5daf5bfbebd7cf748ee' title: 'category 1', SubCats: [ { _id: '61cae5daf5bfbebd7cf748ef' name: 'subcat 1', image: '/assets/images/vr-box-6203301_1920.jpg', }, { _id: '61cae5daf5bfbebd7cf748fb' name: 'subcat 2', image: '/assets/images/galaxy-s20_highlights_kv_00.jpg', }, ] }, ]Por favor ayuda
Controlador :
const deleteSubCategory = asyncHandler(async (req, res) => { const subCategory = await Category.aggregate([ { $unwind: "$SubCats" }, { $replaceRoot: { newRoot: '$SubCats'} }, { $match: { _id: ObjectId(req.params.id) }} ]) if (subCategory) { await subCategory.updateOne({ $pull: {_id: ObjectId(req.params.id)}}) res.json({ message: 'sub-category removed' }) } else { res.status(404) throw new Error('sub-Category not found') } })$update con $pull
db.collection.update({ "SubCats._id": "61cae5daf5bfbebd7cf748ef" }, { "$pull": { SubCats: { _id: "61cae5daf5bfbebd7cf748ef" } } }, { "multi": true })