There is a collection of sights , a sight collection is embedded in it, which has a titleSight field. The problem with the output value of titleSight in the template. Gives the error: Cannot read property 'titleSight' of undefined . How to display the value of the titleSight field?
route.js
app.get('/sight-overall/:id', function (req, res) { Promise.all([ Photo.find({}), Sight.find({_id: req.params.id}) ]).then(function (data) { console.log('data:', data); res.render('sight-overall.ejs', {photoList: data[0], sights: data[1], isAuth: req.isAuthenticated()}); }); sights-overall.ejs
<% var sights = JSON.stringify(sights) %> <% if (locals.sights) { %> <div class="sight-overall__header"> <h2><%= sights.sight.titleSight%></h2> </div> <% } %> data content:


<% var sights = JSON.stringify(sights) %>, make such a variable in ejs, and work with it. - uber42<%= sights[0].sight.titleSight%>add the index - uber42