I'm new to MongoDB, i want to grab all the "posts" that fits createdBy OR to.
router.get('/getPublicProfilePosts/:username',(req,res)=>{
if(!req.params.username){
res.json({success:false,message:"No username provided"});
}
else{
User.findOne({username:req.params.username},(err,user)=>{
if(err){
res.json({success:false,message:'Something went wrong '+err});
}
else{
if (!user) {
res.json({success:false,message:'User not found'});
}
else{
Post.find({createdBy:user.username, to:user.username},(err,posts)=>{ //this one
if(err){
res.json({success:false,message:'Something went wrong '+err});
}
else{
if (!posts) {
res.json({success:false,message:'Posts not found !'});
}
else{
res.json({success:true,posts:posts});
}
}
})
}
}
});
}
});
Post.find({createdBy:user.username, to:user.username} returns an empty array so i guess the statement must respect BOTH createdBy and to.