Answer the question
In order to leave comments, you need to log in
How to display only one account data from MongoDb?
Good afternoon, when studying the database, I encountered that I can not display the data of only one user. That is, registration and login to the account, the user's personal page displays: "Hi, `username`", but along with his `username` appear `username` of other accounts from mongoDB
const isAuth = (req,res,next)=>{
if(req.session.isAuth){
next()
} else{
res.redirect('/login')
}
}
app.get('/register', (req,res)=>{
res.render('register')
})
app.post('/register', async (req,res)=>{
const {username, email, password} = req.body
let user = await UserModel.findOne({email})
if(user){
return res.redirect('/register')
}
const hashPsw = await bcrypt.hash(password, 12)
user = new UserModel({
username,
email,
password: hashPsw
})
await user.save()
res.redirect(('/login'))
})
app.get('/dashboard', isAuth ,(req,res)=>{
UserModel.find({}, function (err, user){
res.render('dashboard',{
userList: user
})
})
})
<h1>Hi,<%userList.find(user =>{ %>
<%= user.username %>
<% })%>!
</h1>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question