Display MongoDB data

Hello,
So I’ve successfully added some data into mongo db using the following function:

addTrip: function(date, car, a, b, dist){
if(!Meteor.userId()){
	throw new Meteor.Error('No access: You are not logged in.');
}

Trips.insert({
userId: Meteor.userId(),
createdAt: new Date(),
date: date,
car: car,
a: a,
b: b,
dist: dist
});

},

How do I display the data in a

now? I need to display only the date, car, a, b and dist. userId is used to show make it so that only subscribed users are able to use it, while createdAt is used for filtering.

My HTML

  <div class="table-responsive">
  <table class="table">
  
     <thead>
      <tr>
         <th>Date</th>
         <th>Car</th>
             <th>A</th>
                 <th>B</th>
     <th>Dist</th>
      </tr>
   </thead>
   
              <tr>
              {{#each trip_html}}

<td class="active"> 
{{name}} {{#if currentUser}} (X) {{/if}}
</td>

   {{/each}}

    </tr>


   </table>
   </div>

My client sided JS (Need help here)


Template.trip_html.helpers({
trip_html: function(){
	
return Trips.find({}, {sort: {createdAt: -1}});
}



});

Do you still have the autopublish package installed? If so, you should be able to see your Trips data now. If you are looking at how to handle publications/subscriptions, then I’d check out https://www.meteor.com/tutorials/blaze/publish-and-subscribe.

No, I’ve removed autopublish. I believe it’s not secure to have it. I am also subscribed, because if in Chrome’s console I write Trips.find().fetch() I do get all my objects from database, however how to I display them now? Like Date in the date field, Location A in Location A field of the table I have for it.

<div class="table-responsive">
  <table class="table">

    <thead>
      <tr>
        <th>Date</th>
        <th>Car</th>
        <th>A</th>
        <th>B</th>
        <th>Dist</th>
      </tr>
    </thead>

    {{#each trip_html}}
      <tr>
        <td>{{date}}</td>
        <td>{{car}}</td>
        <td>{{a}}</td>
        <td>{{b}}</td>
        <td>{{dist}}</td>
      </tr>
    {{/each}}

  </table>
</div>
2 Likes

Wow, this works ideally! Didn’t know that it’s possible to do that. :grinning: Thanks mate.

No worries. If you are going to continue with Blaze, I strongly suggest checking out the documentation: http://blazejs.org

1 Like