Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get items without specific params from MongoDB using Mongoose (NodeJS)

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@example.com'
}

How can I got the same items but without the password param?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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 })
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading