Hello all,
I am trying to fetch posts from particular user who is logged in. the post cannot be seen by other user who is not logged in and also who is not the same user.
I used
router.get('/',(req,res)=>{
Post.find({})
.sort({date:-1}).exec()
.then(posts=>res.json(posts))
.catch(err=>res.status(400).json(err))
});
and in Post model,
const PostSchema = new Schema({
user:{
type:Schema.Types.ObjectId,
ref:'users'
},
title:{
type:String,
required:true
},
description:{
type:String,
required:true
},
date:{
type:Date,
default:Date.now
}
});