Fetching users not followed

We will implement a new API on the server to query the database and fetch this list of users the current user is not following.

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 not in the current user's following list.

mern-social/server/controllers/user.controller.js:

const findPeople = (req, res) => {  let following = req.profile.following  following.push(req.profile._id)  User.find({ _id: { $nin : following } }, (err, users) => {    if (err) {      return res.status(400).json({        error: errorHandler.getErrorMessage(err)      })    } res.json(users) ...

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.