Home > Software engineering >  I want send user info except password from the express server along with jwt token
I want send user info except password from the express server along with jwt token

Time:06-10

I'm creating a MERN stack ecommerce application where I want send all user info along with jwt token but except password I'm ok with token part & I know how to send user but i don't know how to exclude the password property while sending the user through res.json enter image description here

CodePudding user response:

You can use the aggregation or select method in the mongoose.

const users = await User.find({}, {name: 1, email: 1});
or
const users = await User.find({}).select("name email");
or
const users = await User.aggregate([{"$project": {name: 1, email: 1}}]);

CodePudding user response:

Try this -

delete res['password'];

  • Related