Elapsed time between two lines of code REALLY long - why?


#1

I am adding a timestamp when i insert a record in to a collection, like this:

console.log("the current time is--: "+now);
VotesList.insert({ user: Meteor.userId(), flavour: FlavoursList.findOne(selectedFlavour, {fields: {name: 1}}).name, timestamp: now});
console.log("latest record is this: "+ VotesList.findOne({user: Meteor.userId()}, {sort: {timstamp: -1}}).timestamp);

(I have defined the collection, timestamp etc elsewhere.)

In the console, I get the following:

the current time is--: 1448937295592
latest record is this: 1448930788783

which is a difference of 6506809 milliseconds! Why is it returning such a high value?


#2

Are you sure that the record you log is the same as the record you insert?
Maybe the insert failed, so you just log another record that was created 6500 seconds ago.
Try this:

console.log("the current time is--: "+now);
var id = VotesList.insert({ user: Meteor.userId(), flavour: FlavoursList.findOne(selectedFlavour, {fields: {name: 1}}).name, timestamp: now});
console.log("inserted record is: "+ VotesList.findOne(id));

#3

What is the purpose of the variable? Does this refer to the record to be inserted?

How do extract the timecode from the object?


#4

There’s a typo here, which would prevent it from sorting.


#5

i have tried benoits suggestions (with correct spelling;)) - was after some info about the use of the variable and how to get the data from the object…