Pelle Mårtenson
Pelle Mårtenson

Reputation: 40

Show data in meteor-template from array in

I have restaurants in a MongoDB with this structure

"_id" : "R68ZkDqdfj7Qsc9Kx",
"clubname" : "Italiano",
"description" : "Best italian food in town.",
"capacity" : "100",
"createdAt" : ISODate("2016-04-13T16:20:20.683Z"),
"visitors" : [
    {
        "persons" : 0
    }
],
"createdBy" : "mFWrAd3SdyP4dRgEW"

I have no problems retrieving the name, description, capacity... data, but I can't figure out how to read the value 0 in the array under visitors.

In MongoDB I can do:

db.clubs.findOne({_id: "R68ZkDqdfj7Qsc9Kx"}).visitors[0].persons

But how do I do something similar in the Meteor template?

{{visitors}} returns [object Object]

I have also tried

{{#with visitors}}

Upvotes: 0

Views: 41

Answers (1)

David Weldon
David Weldon

Reputation: 64312

visitors is an array, so you you'll probably want to iterate over it and show your data in a list. Here's an example:

<ul>
  {{#each visitors}}
    <li>Persons: {{persons}}</li>
  {{/each}}
</ul>

Upvotes: 1

Related Questions