Hello everyone, my first time here.
So i just started using meteor and moving slowly, so far i was always able to find a solution to my problems but can’t seem to get this one.
Here is the code that seems to be the culprit:
export const TableDelete = new ValidatedMethod({
name: 'table.delete',
validate: Tables.simpleSchema().pick(['_id']).validator({ clean: true, filter: false }),
run({ _id }) {
if (!this.userId) {
throw new Meteor.Error('Tables.methods.TableDelete.notLoggedIn', 'Must be logged in to delete a table.');
}
const userId = this.userId;
return Tables.remove({ userId, _id });
},
});
Here is where i call it:
import { TableDelete } from '/imports/api/tables/methods.js';
function OnTableDelete(event) {
event.preventDefault();
const parent = element.parentNode;
const _id = parent.id;
TableDelete.call({ _id });
}
Template.Table_list.events({
'click .Table_list_delete': OnTableDelete,
});
And here is the error i get from it:
insert failed: Error: Name is required
at getErrorObject (http://localhost:3000/packages/aldeed_collection2-core.js?hash=cd76f0a8f289f873c33e0896e9a86201e64a47d1:489:15)
at TablesCollection.doValidate (http://localhost:3000/packages/aldeed_collection2-core.js?hash=cd76f0a8f289f873c33e0896e9a86201e64a47d1:471:13)
at TablesCollection.Mongo.Collection.(anonymous function) [as insert] (http://localhost:3000/packages/aldeed_collection2-core.js?hash=cd76f0a8f289f873c33e0896e9a86201e64a47d1:223:25)
at TablesCollection.remove (http://localhost:3000/app/app.js?hash=a6ac6bfb70b4466af6485b6db8ff28e912afe5a1:855:55)
at DDPCommon.MethodInvocation.run (http://localhost:3000/app/app.js?hash=a6ac6bfb70b4466af6485b6db8ff28e912afe5a1:786:23)
at ValidatedMethod._execute (http://localhost:3000/packages/mdg_validated-method.js?hash=6427bdae9f989ecfeec537ad65ca5997622e9efb:132:45)
at DDPCommon.MethodInvocation.ValidatedMethod.connection.methods._connection$methods.(anonymous function) (http://localhost:3000/packages/mdg_validated-method.js?hash=6427bdae9f989ecfeec537ad65ca5997622e9efb:92:21)
at http://localhost:3000/packages/ddp-client.js?hash=d69811b75e636077a323c16b077a38a29bacca9e:4077:25
at Meteor.EnvironmentVariable.withValue (http://localhost:3000/packages/meteor.js?hash=27829e936d09beae3149ecfbf3332c42ccb1596f:1077:17)
at Connection.apply (http://localhost:3000/packages/ddp-client.js?hash=d69811b75e636077a323c16b077a38a29bacca9e:4068:54)
meteor.js?hash=27829e9…:930 Error invoking Method 'table.delete': Name is required [400]
I don’t understand the error really, i already have an insert and update method for the exact same collection, using mostly the same syntax when it comes to implementing the method or calling it, but this one is not working for some reason.
I am not sure what the Name
refers to in the error, is it the one in my collection schema i made ? and if so why, i am not picking it in the validation, only the _id
.
Also why is it saying insert failed
when it is a remove
, i mean if it was an insert, then yes, the name
field would be missing because it is required, but i am doing a remove here.