1

I have the following document structure for MongoDB

{
    partnerName: 'Zumba Fitness',
    supportedProducts: [
        'FitBit',
        'Protein Powder'
    ]
}

At the moment I have a delete operation for my Node service, where I am deleting the entire object based on the partnerName.

delete: function (req, res) {
    var removePartner = req.params.partnerName;
    var promise = Partner.find({ partnerName: removePartner }).remove().exec();
    promise.then(function removePartner(val) {
        console.log('partner value removed');
        var response = { message: 'Partner Deleted' };
        res.status(200).send(response);
    }).catch(function catchError(err) {
        console.error(err);
        res.status(500).send(err);
    });
}

How would I modify the above functionality, if I wanted to delete a specific supportedProducts value? For instance if I only wanted to delete "FitBit" in the above document object

user8222014
  • 113
  • 1
  • 1
  • 4
  • Since you cannot see the deleted answer that was given, it mirrors the comment of @Erdenezul ( which I wish they would also delete ) and is incorrect. The correct was to "remove from an array" is using `$pull` as [demonstrated in the linked answer.](https://stackoverflow.com/questions/16959099/how-to-remove-array-element-in-mongodb) – Neil Lunn Jul 11 '17 at 05:36
  • thanks @NeilLunn that worked well for my case – user8222014 Jul 11 '17 at 20:40

0 Answers0