简体   繁体   中英

Error invoking Method 'addNewDriveToSadranTable': Internal server error [500]

I have a problem with Meteor.Call and methods.

I put console.log('test') in the method code. The console shows it, and I can see new doc in the collection for a millisecond (and then it is gone).

what can be the bug?

client/sidurEditor.js

Template.sidurEditor.helpers({
    showForSadran: function() {
        return ForSadranDrives.find({},{sort: {askedDate: 1, since: 1}});
    }

lib/methods.js

Meteor.methods ({
addNewDriveToSadranTable: function (askedDate, since, until, askedDrive, askedUser) {
    console.log('click');
    ForSadranDrives.insert({
        askedDate: askedDate,
        since: since,
        until: until,
        askedDrive: askedDrive,
        driveCar: "chooseCar",
        driveCarName: "car undefined",
        driveDriver: "driver undefined",
        askedUser: askedUser,
        askedNickName: Session.get('nickName'),
        onEditDriveRow: false
    });
    console.log('click2');
} });

collection/collections.js

ForSadranDrives = new Mongo.Collection('forsadrandrives');

The bug was that I wrote a Session inside the method... i putted it in the Meteor.call(...) as argument and it runs great!!

thanks to @masterAM for the comment and the answer

so it look now like that:

client/navbar.js

            Meteor.call('addNewDriveToSadranTable',askedDate, since, until, askedDrive, askedUser, Session.get('nickName'));

lib/methods.js

Meteor.methods ({
addNewDriveToSadranTable: function (askedDate, since, until, askedDrive, askedUser, askedNickName) {
    console.log('click1');
    ForSadranDrives.insert({
        askedDate: askedDate,
        since: since,
        until: until,
        askedDrive: askedDrive,
        driveCar: "chooseCar",
        driveCarName: "אין רכב מוגדר",
        driveDriver: "אין נהג מוגדר",
        askedUser: askedUser,
        askedNickName: askedNickName,
        onEditDriveRow: false
    });
    console.log('click2');
}});

What you are seeing is Meteor's latency compensation - the record is inserted into the local db (minimongo), but disappears when the database refresh from the server occurs. It is most likely because your subscription to the data is either missing or your filter is exluding the data.

You can check by looking for the record in the mongo shell, with the command

meteor mongo

Make sure your cd is in the project directory

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM