errorClass {error: 404, reason: "Method 'nameExample.insert'

I want insert but the console.log in tarjeta.js file sendme this error.
console.log:
imports/ui/components/tarjetaBancaria/tarjeta.js :

  save(){
    insert.call(this.tarjetaBancaria, (err) => {
        console.log('error', err);
    });

this:

errorClass {error: 404, reason: “Method ‘tarjetaBancaria.insert’ not found”, details: undefined, message: “Method ‘tarjetaBancaria.insert’ not found [404]”, errorType: “Meteor.Error”}

imports/api/tarjetaBancaria/collection.js :

import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';

class TarjetaBancariaCollection extends Mongo.Collection {
  insert(doc, callback) {
    const result = super.insert(doc, callback);
    return result;
  }
}

export const TarjetaBancaria = new TarjetaBancariaCollection('tarjetaBancaria');

TarjetaBancaria.deny({
  insert() {return true;},
  update() {return true;},
  remove() {return true;}
});

  const Schema = {};
  Schema.tarjetaBancaria = new SimpleSchema ({
    _id: {
      type: String,
      regEx: SimpleSchema.RegEx.Id
    },
    propietario:  {
      type: String,
      regEx: SimpleSchema.RegEx.Id,
      denyUpdate: true
    },
    nombreApellidos: {
      type: String,
      max : 30,
      min : 1,
      regEx: /^[a-zA-Z-ñáéíóú\s]+$/
    }
  });

  TarjetaBancaria.attachSchema(Schema.tarjetaBancaria);

imports/api/tarjetaBancaria/methods.js

import { Meteor } from 'meteor/meteor';
import {  _   } from 'meteor/underscore';
import { ValidatedMethod  } from 'meteor/mdg:validated-method';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import { LoggedInMixin } from 'meteor/tunifight:loggedin-mixin';
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';

import { TarjetaBancaria } from './collection.js';

export const insert = new ValidatedMethod({
    name: 'tarjetaBancaria.insert',
    mixins: [LoggedInMixin],
    checkLoggedInError: {
        error: '403',
        message: 'Para modificar estos datos necesitas iniciar sesión',
        reason: 'El usuario no loggeado',
    },
    validate: TarjetaBancaria
        .simpleSchema()
        .pick([
            'nombreApellidos'
        ])
        .validator({
            clean: true,
            filter: false
        }),
    run({
        nombreApellidos
    }) {
        const documentoBancario = {
            propietario: this.userId,
            nombreApellidos,
        };
        TarjetaBancaria.insert(documentoBancario);
    }
});

const TARJETAS_BANCARIA_METODOS = _.pluck([
    insert,
], 'name');
if (Meteor.isServer) {
    
    DDPRateLimiter.addRule({
        name(name) {
            return _.contains(TARJETAS_BANCARIA_METODOS, name);
        },
        
        connectionId() {
            return true;
        },
    }, 5, 1000);
}

some ideas?
thanks for your time

Have you registered your method on the server side? Example from todos.

1 Like

You well…
I haven’t imports in the server.

Now works very well

thanks for your time!