Guys I want to $pull
an element from array. Here:
User's Follow:
{ follow:
[ 5edfe8f3bfc9d677005d55ca,
5edfe92fbfc9d677005d55cc,
5ee2326cc7351c5bb0b75f1a ],
follow id:(Which we will pull)
5edfe92fbfc9d677005d55cc
The process:
.
.
User.update(user,{$pull: { follow: friend}}, function(err){
if(err){
console.log(err);
}else{
res.send("Success")
}
});
.
.
Also I have tried with $elemMatch
: Mongodb Unfollow With $pull
Question: How to $pull
specific element from an array?
But it doesnt work. Can someone help me to solve this problem ?
Note: Guys the id's are given as an example to understand well. The follow is the friends of current user. And if user wants to unfollow then it will $pull
the friend(friend: the user on the profile page) Think like facebook's follow-unfollow request. So that if you want to answer please do not give example with id's above because follow id's always change user to user.
So how to pull specific element from an array?
Full Code:
app.post('/cikar/: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")
}
});
});
});
});