W
W
Wasya UK2017-05-03 10:45:04
MongoDB
Wasya UK, 2017-05-03 10:45:04

How to properly pass user information to Node.js?

Selecting a specific user from the database, on the server I get almost complete information about him, including a password with a login. The project is educational, but I would like to know the correct way to pass this data to the template engine to create certain pages.
Transfer the user to Pug, and then he will figure out what and where to insert?
OR
Limit the amount of information on the server, and pass a newly formed user object?
Thanks in advance)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
emp1re, 2017-05-03
@dmc1989

I know 4 ways -
1. Through find - db.collection.find( { _id: "1" }, { item: 1, status: 1 } ) - the second argument leaves the fields you need.
2. Through aggregation - db.collection.aggregate( [ {$match: _id:"1"}, { $project : { item : 1 , status : 1 } } ] ) - $project leaves the fields you need.
3. Form the object of the answer yourself from the result of the sample.
4. db.createView() - a readOnly table is created with the fields you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question