100xdevs-cohort-2 / paytm

205 stars 420 forks source link

whomsoever is login , that name should not be visible in filter data users, or all the users #27

Closed Akshat2Jain closed 4 months ago

Akshat2Jain commented 5 months ago

for eg: If Harkirat is logged in, then he should not see his name coming in the dashboard, it will be stupid if that person is sending money to himself only,

How to tackle this while getting all the users except the user who is logged in?

deepakdevcast commented 4 months ago
  1. Get the id from req.userId
  2. Use "#nor" on User.find()

final code of https://github.com/100xdevs-cohort-2/paytm/blob/backend-solution/backend/routes/user.js from line 121: ` const users = await User.find({'$nor': [{ _id: req.userId }]},{ $or: [{ firstName: { "$regex": filter } }, { lastName: { "$regex": filter } }] })

`

Akshat2Jain commented 4 months ago

Thanks!