0

I have question about getting data form MongoDB with express. I can console.log the correct data, but i'm not able to render it as an .ejs file. It just gives me [object] instead of the actual data. Hope someone can help. I'm very new to express and mongoDB, so it's properly straight forward.

expressApp.get('/home', function(request, response) {

    MongoClient.connect(url, function(err, db) {

        if (err) throw err;

        var dbo = db.db("agile-app-db");

        dbo.collection("Members").findOne({}, function(err, result) {
            if (err) throw err;
            console.log(result);
            response.render('index', {'result' : result})
            db.close();
        });
    });
});


EJS FILE 
<ul>
    <li><%= result %> </li>
</ul>
egx
  • 389
  • 2
  • 14
  • Does this answer your question? [Express and ejs <%= to render a JSON](https://stackoverflow.com/questions/13788314/express-and-ejs-to-render-a-json) – MattB Oct 23 '20 at 19:06

1 Answers1

0

Please see Express and ejs <%= to render a JSON

 <%- JSON.stringify(result) %>
MattB
  • 1,104
  • 8
  • 15