michelson / dante2

A complete rewrite of dante editor in draft-js
https://michelson.github.io/dante2/
Other
912 stars 121 forks source link

$pull Query Doesnt Work #231

Closed Alpgul02 closed 4 years ago

Alpgul02 commented 4 years ago

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.