I have NodeJS API with Mongoose to connect to MongoDB
To get all items from a collection I do this: const users = db.users.aggregate()
This is a example user:
{
name: 'Name',
password: '$2a$10$fe', // the password is encrypted
email: '[email protected]'
}
How can I got the same items but without the password param?
CodePudding user response:
use the projection action from the aggregation pipeline:
db.users.aggregate([ {
$project: { password: 0 }
}])
Also if you're not going to use the aggregation pipeline, use the find method instead:
db.users.find({}, { password: 0 })