Can't move Array to Template

Hello,
it is pretty Basic but I am stuck now for at least 2 days on that.
My mongo Collection looks like this.

{
_id: “C7700255”,
WorkCenters: [ {
workCenter: “L4MSB010”,
waitTime: “20”,
processStartTime: 1458277608466,
processDuration: “2”,
issuesTotal: “2”,
downTime: 20
} ] }

My helper Template

Template.hello.helpers({
center: function () {
var center_data = RecorderApp.find({_id: “C7700255” }).fetch();
console.log(center_data);
return center_data;
}
});

and my html:

<template name="mainLayout">
test
{{> hello}}
</template>
<template name="hello">
    {{#each center}}
    {{workCenter}}
    {{waitTime}}
    {{processStartTime}}
    {{processDuration}}
    {{issuesTotal}}
    {{downTime}}
    {{/each}}
</template>

In tne console I can see the array with all informations, but my template does not rendering anything.
I tried a lot of things but the best I got was [object Object]
I am a bit lost now :confused:
Every hint would be greatfull apreciated.
thanks

Have your template helper return center_date.WorkCenters?

I tried it with your suggestion, but sadly it does not work.

Template.hello.helpers({
  center: function () {
    var center_data = RecorderApp.find({_id: "C7700255"}).fetch();
    console.log(center_data);
    return center_data.WorkCenters;
  }
});

Thank you

Also take.fetch() off

Still not working :sweat:

Template.hello.helpers({
  center: function () {
    var center_data = RecorderApp.find({_id: "C7700255"});
    console.log(center_data);
    return center_data.WorkCenters;
  }
});

When I use an array instead of the database request it will render

center_data = [
{
workCenter: “L4MSB010”,
waitTime: “15”,
processStartTime: 1458277608466,
processDuration: “20”,
issuesTotal: “1”,
downTime: 3
}
];

So your collection/doc structure is a bit odd, and trying to use the blaze examples isn’t going to work because of that. WorkCenters is an array of objects, so you need to treat it like that. Try:

Template.hello.helpers({
  center: function () {
    var center_data = RecorderApp.find({_id: "C7700255" });
    console.log(center_data);
    return center_data;
  }
});


<template name="hello">
  {{#each center}}
    {{#each WorkCenters}}
      {{workCenter}}
      {{waitTime}}
    {{/each}}
  {{/each}}
</template>
1 Like

Its working now, thank you so much. :smiley:
About the structure, I will do I do some tutorials for proper database structure .
I thought it is a good idea to do it like it is…

I don’t think there is inherently a problem with the structure, if you have multiple WorkCenters for each document in your collection. But it looks like each workCenter is its own document. If that’s the case, I’d have all of these attributes (waitTime, downTime, etc) at the root of the document:

{
  _id: "C7700255",
  workCenter: "L4MSB010",
  waitTime: "20",
  processStartTime: 1458277608466,
  processDuration: "2",
  issuesTotal: "2",
  downTime: 20
}

But, if you have multiple workCenters for each doc, then your structure makes sense:

{
  _id: "C7700255",
  WorkCenters: [ 
    {
      workCenter: "L4MSB010",
      waitTime: "20",
      processStartTime: 1458277608466,
      processDuration: "2",
      issuesTotal: "2",
      downTime: 20
    },
    {
      workCenter: "D5DDB010",
      waitTime: "20",
      processStartTime: 1458277608466,
      processDuration: "2",
      issuesTotal: "2",
      downTime: 20
    }, 
  ] 
}

Thank you for your reply.
There are 40 WorkCenters and a Machine has to pass each workcenter. I want to monitor
each workcenter for downtime, wait time, repair time…
Thatswhy I was structuring the doc as it is.
It makes me feel good to hear I am on the right path at least with the database Structure.
Thank you

No prob, glad to help! Good luck =)