Question

I have the nodejs express script as below

app.get('/approval',function(req,res){

        db.open(function(err,db) {
        var collection = db.collection('form');
    collection.find({ contact: 'James Wong' }).toArray(function(err, docs) {
        console.log(docs); 
   /*It will  will give an output something like
      { _id: 53533045fec60bd941c04a22,
       contact: 'James Wong'} */


        res.render('approval.handlebars',{resultfind : docs});
           /*it will give an output as [object Object]

        db.close();
      });

    });

My console.log(docs) output is in JSON ARRAY format which is correct. i.e

{ _id: 53533045fec60bd941c04a22,
       contact: 'James Wong'} */

However when I display it in handlebartemplate by using res.render the result will be as below;

[object Object]

My template is below

<div>
{{resultfind}}
</div>

I wanted to access those object properties.

Was it helpful?

Solution

Got it resolved ..Thanks to TheShellfishMeme .

Two things to do

1) instead of toArray function , replace it by each function . This is to maintain json format

2) to access the JSON format at the html {{resulfind.contact}}

Cheers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top