0

I am using Express, NodeJS and MongoDB . Trying to use handlebars to pass some info to render.

the route code im using is:

router.get('/mediciones', async (req, res) => {
  // res.render('mediciones');
  const dashboard  = await Mediciones.find().limit(3);
  console.log(dashboard);
  res.render('mediciones' , { dashboard });
});

the hbs code is:

{{#each  dashboard }}
<p>
    {{!-- {{this}} --}}      // using just one, but both show me the 3 objects
    {{.}}
</p>
{{/each}}

the rendered view:

{ _id: 5ea9ff48b54a2b09d38ddfd9, temperatura: 20, humedad: 44, heat: 19.2, temperaturaagua1: 22.31, temperaturaagua2: 22.31, ventilador: true, extractor: true, intractor: true, bombaagua: true, refreshInterval: 10000, currentMillis: 3799956, dia: 2020-04-29T22:27:20.997Z, __v: 0 }

{ _id: 5ea9ff52b54a2b09d38ddfda, temperatura: 20, humedad: 44, heat: 19.2, temperaturaagua1: 22.31, temperaturaagua2: 22.31, ventilador: true, extractor: true, intractor: true, bombaagua: true, refreshInterval: 10000, currentMillis: 3809961, dia: 2020-04-29T22:27:30.986Z, __v: 0 }

{ _id: 5ea9ff5db54a2b09d38ddfdb, temperatura: 20, humedad: 44, heat: 19.2, temperaturaagua1: 22.31, temperaturaagua2: 22.31, ventilador: true, extractor: true, intractor: true, bombaagua: true, refreshInterval: 10000, currentMillis: 3820030, dia: 2020-04-29T22:27:41.068Z, __v: 0 }

The problem is: how can i just exract "temperatura" and "humedad" from those objects and print them on a <p> tag? i tried to use {{temperatura}} but nothing show. I cant find the answer

Tomas Bond
  • 35
  • 1
  • 7

2 Answers2

1

try this.

const dashboard  = await Mediciones.find().limit(3).lean();
Satyendra07
  • 139
  • 5
0

What if you did

{{#each  dashboard }}
<p>
    {{temperatura}} //       // using just one, but both show me the 3 objects
    {{humedad}}
</p>
{{/each}}

?

Kasey Chang
  • 532
  • 4
  • 12