Home > Back-end >  How to get items without specific params from MongoDB using Mongoose (NodeJS)
How to get items without specific params from MongoDB using Mongoose (NodeJS)

Time:08-10

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 })
  • Related