Can't set timers inside simulations (SOLVED)

I am trying to remove a checkin document by playersId and between a date range and keep getting the following error:

“Exception while simulating the effect of invoking ‘deleteCheckin’ Error: Can’t set timers inside simulations(…) Error: Can’t set timers inside simulations”

here is my code. Any idea why i’m getting that error? Thanks in advance.

on client.

  //asign var to id feild of the player
    var playerId = this._id;
        //attach the id to the session
    Session.set('selectedPlayer', playerId);
        //assign var to get the session/id
    var selectedPlayer = Session.get('selectedPlayer');

        //pass delete call to server side meteor method for security
    Meteor.call('deleteCheckin', selectedPlayer)

On the server

//in lib directory
Meteor.methods({

'deleteCheckin': function(selectedPlayer){
  //start of day
  //  var startOfDay = moment().startOf('day');
  var startOfDay = new Date();
  startOfDay.setHours(0,0,0,0);
  //end of day
  var endOfDay = new Date();
  endOfDay.setHours(23,59,59,999);
   
checkins.remove( {playersId: selectedPlayer},{ createdAt: { $gt: startOfDay, $lt: endOfDay} } )

 },
});//end meteor methods`

To help troubleshoot - are you making any Meteor.setTimeout, Meteor.setInterval or Meteor.defer calls anywhere in your code?

No that is the weird thing. The only thing i have is is a setDate elseware in my code.

since it said simulation error, I guess you can try to put the method in the server side only to see whether it has an error, I think that can help to debug the issue.

dont you have something binded to that remove operation?
maybe some collection hooks or schema autovalues etc?

no hooks and not using a schema

does it have anything to do with the session?

the error goes away when i use

checkins.remove( {playersId: selectedPlayer} )

but the issue is then it removes all records with that id instead of just the one i want.

lol, what is that $lg ? :smiley:
u probably wanted $gte/$gt or something like that.

@shock yes thanks that was definitely a typo. lol error still exist though after change.

your whole createdAt is as 2nd argument, instead of be part of the first argument so it is being taken as callback function or such… probably

1 Like

@shock that was the tip I needed. Thank you for helping me out. I only spent 5 1/2 hour trying to figure this out. :frowning: You were right. It was interpreting my createdAt as the the 2nd argument instead of the first. It’s always the little things that i get hung up on.

I fixed the query and i have it working now. I replaced my query with the following if it helps anyone in the future.

checkins.remove({'playersId':selectedPlayer,'createdAt': { $gt: startOfDay, $lt: endOfDay}})

Thanks everyone for helping.