1

I have problems with inserting data to collection, it says in console: Error invoking Method 'addReservation': Internal server error [500] This is my reservation template:

<template name="reservations">
    <div class="container-fluid registration-form">
        <form class="new-reservation">
            <div class="row">
                <input type="text" name="title"/>
 </div>
            <button type="submit" class="btn btn-success">Add reservation</button>
        </form>
        <div class="row">
            <div class="col-md-6">
                <ul class="list-inline">
                    {{ #each reserve}}
                    {{ >reservationForm }}
                    {{/each}}
                </ul>
            </div>
        </div>
    </div>
<template name="reservationForm">
    <li>{{title}}</li>
</template>

And this is js file:

NewReservations = new Mongo.Collection('reserve');

in isClient:

Template.reservations.helpers({
        reserve: function(){
            return NewReservations.find();
        }
    });

    Template.reservations.events({
        'submit .new-reservation': function(event){
            var title = event.target.title.value;
            Meteor.call("addReservation", title);
            event.target.title.value = "";
            return false;
        }
    })

and this is isServer

Meteor.methods({
        addReservation: function(title){
            NewReservations.insert({
                title: title
            });
        }
    })

I deleted insecure and autopublish. enter image description here

  • Try logging `title` on the server before you insert. Is it what you're expecting? – richsilv Jan 20 '16 at 10:17
  • You have a scope issue. Your `NewReservations` collection does not seem to be accessible from the method body. – Kyll Jan 20 '16 at 10:27
  • Possible duplicate of [Global variables in Meteor](http://stackoverflow.com/questions/27509125/global-variables-in-meteor) – Kyll Jan 20 '16 at 10:27

1 Answers1

1

your server console says that NewReservations is not defined, which implies that your server is not finding this variable/database. The only possible problem i see is that you've not defined your database in the both scope. I mean you might have defined your db in client side or server side only.

basically you need to put

NewReservations = new Mongo.Collection('reserve');

outside of Meteor.isClient and Meteor.isServer block.

Faysal Ahmed
  • 1,592
  • 13
  • 25