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

Francesco Sasso

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?

Mehdi Fracso

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Get data from mongodb with dynamic nested levels using nodejs and mongoose

Get an element from an array of objects with an id in mongodb using nodejs and mongoose

How to remove data from mongodb collection using nodejs and mongoose

Angular 2: how to get params from URL without using Routing?

How to read the specific data from mongodb using mongoose?

How to get data from multiple collections in mongodb using mongoose?

How to get the value from a mongoose/mongodb document after using findOne()

How simultaneously find documents and get their count from mongodb using mongoose

How to get a specific object in mongoose with mongoDB?

How to get data back from Mongoose without using a callback?

Cannot xor mongodb field from nodejs without mongoose

How to get more items from documents using mongoDB shell?

NodeJS - WITHOUT EXPRESS - how to get query-params?

GET an object from mongodb using mongoose

how to GET data from mongodb and transfer it to Html page using nodeJS?

Using Django, how to reload specific button params without reloading the page?

Retrive Data from MongoDB using NodeJS with Mongoose with paging

Sort based on how many items are in an array using mongoose and MongoDB

How to update items for a day in mongoose/mongodb from UTC to local time

How to get the connected objects within a collection in an array in Mongoose MongoDb NodeJS

how to copy or clone a document in MongoDB Collection using mongoose and nodeJS

how to add a new line into mongodb using mongoose express and nodejs

get Data from a collection in MongoDB using NodeJS

How to remove the specific element in an array of objects in mongoose using nodejs?

How to delete property from object mongoDb mongoose nodeJs

how to get the specific result according to a certain condition in MongoDb through mongoose

How to get slave status of mongodb using nodejs?

How can I connect to mongodb using express without mongoose?

How to populate in MongoDB without mongoose?