Michael
Michael

Reputation: 127

Meteor insert doesnt work

normally my inserts are working fine but today i could crush Meteor ;)

I already removed insecure and Autopublish and checked the code hundred times but the insert gets not executed.

My hmtl:

<template name="neuesGebietErstellen">
    <div id="viewport">
        <form class="add-Gebiet">
            <input type="text" name="Gebietsname" placeholder="Gebietsname"><br>
            <input type="text" name="Gebietsnummer" placeholder="Gebietsnummer"><br>
            <input type="text" name="Ort" placeholder="Stadt / Ort"><br>
            <input type="submit" value="Gebiet hinzufügen">
        </form>
    </div>
</template>

my js:

import { Meteor } from 'meteor/meteor'

Template.neuesGebietErstellen.onCreated(function () {
    this.subscribe('gebiete');
});


Template.neuesGebietErstellen.events({
    "submit .add-Gebiet": function (event) {
        var Gebietsname = event.target.Gebietsname.value;
        var Gebietsnummer = event.target.Gebietsnummer.value;
        var Ort = event.target.Ort.value;

        Meteor.call('neuesGebiet', Gebietsname, Gebietsnummer, Ort)

        console.log("hat geklappt");
        return false; 
 }
});

My method file in the server folder:

Meteor.methods({
    neuesGebiet(Gebietsname, Gebietsnummer, Ort) {
        console.log("Methode wurde aufgerufen");

         Gebiete.insert({            
            Gebietsname: Gebietsname,
            Gebietsnummer: Gebietsnummer,
            Ort: Ort
        });        
    }
});

The strange part is i get both console logs so my event is executed and the method is called too but with meteor toys i check my collection and there nothing is getting inserted. So please help me ;)

Upvotes: 0

Views: 60

Answers (2)

Michel Floyd
Michel Floyd

Reputation: 20226

Usually the problem is that the record is being inserted but is not being published back out to the client so the client never sees it.

  1. Have you removed the autopublish package? If so...
  2. Are you publishing your Gebiete collection from the server and
  3. Are you subscribing to it on the client?

Upvotes: 1

Planetary Dev
Planetary Dev

Reputation: 51

Make sure you have the collection-object Gebiete declared/defined as well like this.

let Gebiete = new Meteor.Collection('gebiete');

Upvotes: 0

Related Questions