Closed SohaibArbiBakcha closed 3 years ago
Hello @SohaibArbiBakcha
I'm not 100% sure, but it looks like that this is not mongoose's issue.
This block if (files.photo) {...}
does not execute. This occurs because files.photo
is falsy.
So you should check:
requireSignin
middlewareHmm. Since you are not showing what is your expected output, I cannot see what is the problem here. The reference feature seems to be working as intended (Although I remember that it is mongoose.Schema.Types.ObjectId
, not mongoose.Schema.ObjectId
). Anyhow, a reference field is for storing the IDs of the related document(s). To get the entire User Document, you will need to use Query population
@Kamikadze4GAME @baohuynhlam
its an API when i use populate method i got the whole user objects they are no problem
thank a lot for your answers
exports.getPosts = (req, res) => { Post.find() .populate("postedBy", "_id name") .select("title body") .then((posts) => { res.status(200).json({ posts }); }) .catch((error) => console.log(error)); };
my user Schema
My post Schema
find user by id method
post method
my route
result i recive when trying to create a post by a user