michelson/dante2

$pull Query Doesnt Work

Alpgul02 opened this issue · 0 comments

Hey, I have a system that user can follow and now I am trying to do unfollow request with $pull.

This is my stackoverflow question: https://stackoverflow.com/questions/62730273/mongodb-nodejs-pull-element-from-an-array

This is my app.js:

app.post('/unfollow/:id', function(req, res){

  User.find(req.user
  
  ).exec(function(err, user){
  
  if(err){
    console.log(err);
  }
    
    User.find({"username":req.params.id}, function(err, friend){
      
      if(err){
        console.log(err);
      }
    User.update(user,{$pull: { follow: friend}}, function(err){
      if(err){
      console.log(err);
    }else{
      res.send("Success")
    } 
    });
  });
  });
  });

In this process, friend and user is whole object. But follow’s type is referred as a ObjectID in models.js

So that it just pushs or pulls the _id of the friend.

I want to update user follower by pulling friend _id.

NOTE: Same codes with $push and $addtoset
İnstead of $pull works fine when I want to make a follow request.