Mongoose deleting (pull) a document within an array, does not work with ObjectID

后端 未结 7 1518
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 16:35

I have the following mongoose schema:

user = {
    \"userId\" : \"myId\",
    \"connections\":
    [{
        \"dateConnectedUnix\": 1334567891,
        \"is         


        
7条回答
  •  独厮守ぢ
    2020-11-27 17:10

    I have a document like

    I have to delete address from address array

    After searching lots on internet I found the solution

     Customer.findOneAndUpdate(query, {$pull: {address: addressId}}, function(err, data){
            if(err) {
              return res.status(500).json({'error' : 'error in deleting address'});
            }
    
            res.json(data);
    
          });
    

提交回复
热议问题