Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removeFriend Parameter #12

Open
jars-are-red opened this issue Jun 12, 2018 · 3 comments
Open

removeFriend Parameter #12

jars-are-red opened this issue Jun 12, 2018 · 3 comments

Comments

@jars-are-red
Copy link

Within the removeFriend function, what is expected when asking for user1 and user2 ? When given the "_id" field, it does not return an error but does not remove each user from the friends attribute. In requestFriend, the parameters are user1._id and user2._id so I was thinking delete would be the same.

@stikbomb
Copy link

same problem. try something like this (its work for me)
`exports.removeFriend = (req, res) => {
User.findOne({_id: req.session.passport.user._id}, (err, master) => {
if (err) throw err;
User.findOne({_id: req.body.reqUser}, (err, user) => {
if (err) throw err;
User.removeFriend(master._id, user._id, (err, byeFriend) => {
if (err) throw err;
res.sendStatus(200);
})
})
});

};`

@amack2u
Copy link

amack2u commented Sep 4, 2018

you need to convert your id, which is most likely a string to a mongoose type object id.
example:
//substitute yourStringUser1Id, yourStringUser2Id with your ids.
var mongoose = require('mongoose');
var user1Id = mongoose.Types.ObjectId(yourStringUser1Id);
var user2Id = mongoose.Types.ObjectId(yourStringUser2Id);
User.removeFriend(user1Id, user2Id, cb);

@Muhammed255
Copy link

you need to convert your id, which is most likely a string to a mongoose type object id.
example:
//substitute yourStringUser1Id, yourStringUser2Id with your ids.
var mongoose = require('mongoose');
var user1Id = mongoose.Types.ObjectId(yourStringUser1Id);
var user2Id = mongoose.Types.ObjectId(yourStringUser2Id);
User.removeFriend(user1Id, user2Id, cb);

Thank you, it worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants