Am trying to allow a user to get posts by categoryIndex. My postSchema has a categoryIndex which the user chooses when they are posting something. For example if a using is posting something in the category of BOOKS they will automatically send the categoryIndex of BOOKS to the backend. My problem is sorting the posts by the categoryIndex. here is my code http://ift.tt/2tOiOKb export async function getPostByCategoryIndex(req,res,next) { //req.query will give me {categoryIndex:'2'} //so i parse the string 2 into int const categoryIndex=parseInt(req.query.categoryIndex) console.log(categoryIndex) const posts= await Post.find({categoryIndex:categoryIndex})res.status(httpStatus.OK).json({ code:0, data:posts }) } here is my post data http://ift.tt/2umYnRv so i want to be able to get posts by the categoryIndex
Submitted July 04, 2017 at 10:16PM by francishero
No comments:
Post a Comment