Id: undefined in Meteor.methods using Meteor.userId()

hi,
i trying get the userid in the server side whit Meteor.methods() , But I’m still getting undefined.
I simply want to get the userId () to be able to stop the reminder in which I am working.

In my other methods it works using insert and udapte so I can not understand why I keep getting undefenied

The code is as follows.


import moment from 'moment';
import { Meteor } from 'meteor/meteor';

Meteor.methods({
  timer1: function(timer){
    console.log("metodos Timer");
    console.log(timer);
      var id= Meteor.userId();
    console.log('id:',id);
    var data = AddPerson.find({ userId: "3aNo4by6miwqdN2Qv"}).fetch();
    l = data.length;
    console.log('data-l',l);
    for (var i = 0; i < data.length; i++) {
      console.log(data[i].hora)
      var timer2 = moment(timer).format('HH:mm');
      console.log('timer2:',timer2);
      if (timer2 === data[i].hora){
        console.log("STOP")
        SyncedCron.stop();
      } else {
        console.log('contando.');
        console.log('contando..');
        console.log('contando...');
      }
    }
  }
})

On the server side you usually get the userid with this.userId. In your code you also set var id but then use userId in your query

hi thanks, If I try too that way and nothing is still getting id: null

Add a console.log(data) if you even get the documents you are looking for

@jamgold
Return data: [], that’s what I do not understand because it does not take the value of meteor.userid () or this.userid

That is because you are not using the userId. Try this

    var userId = this.userId;
    console.log('id:',userId);
    var data = AddPerson.find({ userId: "3aNo4by6miwqdN2Qv"}).fetch();

in your original code snippet you accessed userId which was not defined

Finally get resolve
var data = AddPerson.find ({id: this.userId}) fetch ();
Thanks for the help