this is what my data looks like
{ _id: 5a114dede58f4a05cb135d96,
messages: [
{
id: 5a114c66e58f4a05cb135d8c,
User: 'developer2',
_id: 5a114e26e58f4a05cb135d9b,
texts: [{
_id: 5a114e26e58f4a05cb135d9d,
message: 'hii',
username: 'ruby'
},
{
_id: 5a114e40e58f4a05cb135d9e,
message: 'es',
username: 'shan'
}
] } ]
}
}
how do I extract all data from texts, I'd used this but this not returning any thing
<% texts.messages.texts.forEach(function(text){ %>
<p><%=text.message%></p>
<p><%=text.username%></p>
<% }) %>
**Edit:when i just printing
<%=texts%>
**{ _id: 5a114dede58f4a05cb135d96,
messages: [ { id:
5a114c66e58f4a05cb135d8c,
User: 'developer2', _id:
5a114e26e58f4a05cb135d9b,
texts: [Array] } ]
}
I'm not able to see data inside texts unless I print this
<%=texts.messages%>
*this is what i get after writing texts.messages *
{
texts: [{
_id: 5a114e26e58f4a05cb135d9d,
message: 'hii',
username: 'ruby'
},
{
_id: 5a114e40e58f4a05cb135d9e,
message: 'es',
username: 'shan'
}
] } ]
}
}
My route to transfer data to ejs
User.findOne({username:req.user.username},{messages:
{ $elemMatch: {
User:req.params.username} }},
function(err,data){
if (err) {
throw err;
} else {
res.render("chat",{texts:data,user:founduser});
}
})
what am I missing here ?
<% texts.messages.forEach(function(message){
message.texts.forEach(function(text){ %>
<p><%=text.message%></p>
<p><%=text.username%></p>
<% }})) %>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments