April 2020
Intermediate to advanced
716 pages
18h 55m
English
We will implement a new API on the server to query the database and fetch the list of users the current user is not following. This route will be defined as follows.
mern-social/server/routes/user.routes.js:
router.route('/api/users/findpeople/:userId') .get(authCtrl.requireSignin, userCtrl.findPeople)
In the findPeople controller method, we will query the User collection in the database to find the users that are not in the current user's following list.
mern-social/server/controllers/user.controller.js:
const findPeople = async (req, res) => { let following = req.profile.following following.push(req.profile._id) try { let users = await User.find({ _id:{ $nin : following }}) .select('name') res.json(users) }catch(err){ ...Read now
Unlock full access