I am querying users collection and I don't want to send back password. My main point is that if I can perform javascript operations on mongodb objects or not. Here is my code:
router.get("/:userId", async (req, res) => {
try {
const user = await User.findById(req.params.userId);
delete user.password;
if (user.parent !== undefined) {
const referrer = await User.findOne({ _id: user.parent });
return res.json({ user, referrer });
}
res.json(user);
} catch (error) {
res.status(400).json(error);
}
});
I am getting this output
{
"is_deleted": false,
"packages": [],
"_id": "5ed102f3fefa080404db01df",
"name": "parent",
"email": "parent@parent.com",
"gender": "m",
"password": "$2b$10$HTGaoy.AVmoG/A0c/vkikO0NnEBte7f2tvwt2FQE94bZlNiYTeX8i",
"__v": 0
}
I tried to perform filter on a list of mongodb objects and that failed too.