I'm making an order online page on a food website in meteor. For this, I have made an order online collection. Now I'm trying to add dishes to my collection

The problem is unlike other pages in the website, I can’t give any kind of form on this page to take user input and store that input in the database.

I am adding the dishes specifications like name, price etc. directly in the collection through the command line but the problem is when I’m trying to iterate these dishes on to my order online page through a helper function, I’m getting an exception in template helper: order_online error at the console. Please help how can resolve this problem?

  1. We’ll need to see some code - templates, helpers etc.

  2. What are you doing here exactly - examples, please.

    I am adding the dishes specifications like name, price etc. directly in the collection through the command line

import { Mongo } from ‘meteor/mongo’;

export const Order_online = new Mongo.Collection(‘order_online’);

This is my collection.

import { Meteor } from ‘meteor/meteor’;
import { Order_online } from ‘…/order_online.js’;

Meteor.publish(‘order_online.all’, function(){

      return Order_online.find();

});

This is my publication.

import “./order-online.html”;
import “…/…/components/navbar/main_navbar.js”;
import “./order-online.css”;
import “…/…/components/footer/footer.js”;

Template.order_online.onRendered(function(){
this.subscribe(“order_online.all”);
});

Template.order_online.helpers({
order_online: function(){

    return Order_online.find();

  }

});

This is my helper and subscription.

{{#each order_online}}

      <h3>{{name}}</h3>
      <p>{{desc}}</p>

    <button class="crt">Add To Cart</button>
  
{{/each}}

This is how I’m trying to iterate the values inserted into the collection through a query in command line as follows:

meteor:PRIMARY> db.order_online.insert({name: “tuna3”, desc: “sweet3”, price: “59”});

I’m expecting tuna3, sweet3 and 59 to be shown on the order_online page as a result of all of the above code but it’s giving me exception in template helper : order_online error at the console.

Please edit your post and ensure each code block is wrapped in triple-backticks, like this:

```
your
code
here
```

to make it easier to read.

Things I can see so far:

  • import { Order_online } from '…/order_online.js';
    • There’s no such thing as ... as a path specifier. Those ... are throughout your code. Are you using ESLint to check your syntax?
  • this.subscribe("order_online.all");
    • that really belongs in your onCreated.
  • {{#each order_online}}
    • you seem to have a template and a helper with the same name. As you haven’t provided your <template name= I can’t be sure. That’s probably OK, but very confusing.
  • You haven’t made it clear where these files are (what folders they’re in). That would be helpful.
  • Using the MongoDB shell to insert documents without an _id means they get created with MongoIds, not strings. For what you seem to be doing at the moment, that should still work, but you may want to rethink that.

I’m doing this at the mongo shell to insert data into my collection: db.orderonline.insert({dishname: “Sushi”, dishprice: “99”})

Now I want to iterate these values in my template and I am doing so using a helper as {{dishname}} and {{dishprice}}. I expect Sushi and 99 to be shown on my webpage. But it’s just not happening and I’m getting exception in my template helper: orderonline error.

I’ve thought about this a lot and I don’t understand why my helper is not throwing the information to my DOM from the collection.

Somehow I have managed to get everything in place and everything is working fine. I have a cart template embedded in my order_online template. Now the dish that I have rendered (iterated) from the database(collection) on to my order_online template through a helper, I have given an add button below the dish. Please tell me what method should I write so that when I click on the add button, the dish gets rendered into the cart template. I know I need to write publication and subscription for the cart template as well but by going this way the dishes will get rendered to the cart automatically, I want them rendered only when I click on add. Please help!

The easiest way is probably to call a Meteor method when the button’s clicked.

The method would then insert the appropriate reference into the “cart collection”.