Calculating time difference (.getTime() + mongoDB $gt)

Hi, for my app i need to bring back from a collection all the people that were online on the past 30 mins (if someone was online 31 mins or more ago he won’t be returned).

I want to do most of the calculations on the client, so on the “on login” I calculate:

  1. the new Date(),
  2. getTime(),
  3. getTime() - 30 mins

and call a method on the server.

const date = new Date(); 
const time = date.getTime();
const thiry_mins_ago = time - 1806000;'find_active_friends', thiry_mins_ago);

on the server i find() all the users with the “last_login” time grater than thiry_mins_ago, besides the actual user.

find_active_friends(thiry_mins_ago) {
        let online_friends = UsersSummery.findOne( {"userId": {$ne: userId} }, {"last_login": {$gt: thiry_mins_ago} } );

however, on the test i did i got back a user with last login of 12367, while the thiry_mins_ago was 1501574394951.

any idea what did i do wrong?


Firstly, you could just use:

const thirty_mins_ago = - (30 * 60 * 1000); // NB that's 1,800,000ms not 1,806,000

How do you setup last_login? Is it seconds, milliseconds, etc.? Which epoc is it relative to? (1970?)
(By the way, typos: grater => greater, thiry => thirty, Summery => Summary)