Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question