Hi, to explain my app briefly: I have a User Schema and a "Tweet" Schema (Actually it's a 'Post' Schema but to avoid confusion with the 'post' method let's call it a "Tweet Schema').
User's have many "tweets" , but a "tweet" only has one User (like twitter). Inside my tweet schema I have a key of Original_Poster, which is a reference to the id of the User who created the post (see below for schema).
In a route to update a tweet, I have an if else statement to confirm if the tweet that the user is trying to update, is actually their tweet. This is functioning while using locally created users with mongodb/mongoose, but not with users created through passport-facebook.
Here is the if else statement:
if(req.user._id == post.original_poster){
console.log('nice')
}else{
console.log(req.user._id, post.original_poster);
console.log(typeof req.user._id, typeof post.original_poster)
console.log('wtf')
}
What I expect to see is in my console is: 'nice'
What I am actually seeing is:
5a288913fa0d78257fd7b4d3 5a288913fa0d78257fd7b4d3
object object
wtf
Clearly they are the same user ids, and the type is the same (though this shouldn't matter as I am using the double equals not the triple equals).
Can anyone explain this?
Edit: Here is the full Post.find({}) for more info:
Post.findOne({_id: req.params.id}).then((post)=>{
if(req.user._id == post.original_poster){
console.log('nice')
}else{
console.log(req.user._id, post.original_poster);
console.log(typeof req.user._id, typeof post.original_poster)
console.log('wtf')
}
})