J
J
jedifa2021-07-30 06:10:32
Node.js
jedifa, 2021-07-30 06:10:32

Is it possible to filter objects that came with MongoDB?

Please tell me, I receive data from MongoDB

[{
    "_id": "61014061f992e20021e7ccaf",
    "email": "[email protected]",
    "username": "test",
    "password": "$2a$12$y3ujbKJ4MugN6EvHNqNA.uTMSCejpTzwMT4jN8Imd5beTqlF6M4eO",
    "__v": 0
}, {
    "_id": "61013f817e9fd3ffdf9c150a",
    "email": "[email protected]",
    "username": "test1",
    "password": "$2a$12$0TNS6fueOBpUtzWhcHSecOlu3./uvK1kjcaznwCLuRVOTgoHpU1Um",
    "__v": 0
} 
]

Is it possible to send everything except the password to the frontend? How can this be filtered out?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Confy, 2021-07-30
@jedifa

Project Fields to Return from Query
or via
Model.find()

const cursor = db
  .collection('users')
  .find({ email: '[email protected]' })
  .project({ password: 0, __v: 0 }); // 0 означает исключить

// или через модель

someModel.find({}, { password: 0, __v: 0 }).then(console.log);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question