From f134bda92fe37b8dfd8d23a2ce771d7d00afb01b Mon Sep 17 00:00:00 2001 From: deepak Date: Thu, 9 May 2024 21:45:28 +0530 Subject: [PATCH] remove extra map Mongoose Find provides a select specific fields from data reference: https://stackoverflow.com/questions/24348437/mongoose-select-a-specific-field-with-find --- backend/routes/user.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/backend/routes/user.js b/backend/routes/user.js index 3f702178..81e17c13 100644 --- a/backend/routes/user.js +++ b/backend/routes/user.js @@ -128,16 +128,14 @@ router.get("/bulk", async (req, res) => { "$regex": filter } }] + },{ + username: 1, + firstName: 1, + lastName: 1, + _id: 1 }) - res.json({ - user: users.map(user => ({ - username: user.username, - firstName: user.firstName, - lastName: user.lastName, - _id: user._id - })) - }) + res.json(users) }) -module.exports = router; \ No newline at end of file +module.exports = router;