Having Consistent Client's Session ID in the Meteor Collection

When a new client connects to the server, the server inserts a record containing the client's Meteor.default_connection._lastSessionId as the uuid field into the Collection named Active.

However whenever the server resets, the client is assigned a new Meteor.default_connection._lastSessionId while the record containing the previous _lastSessionId still remain in the Collection.

Question: How can we detect the reconnection event, and update the record containing the old _lastSessionId with the new one?

Or can we somehow prevent the _lastSessionId from changing?

client/main.js

Meteor.startup(function() {
    Meteor.call('active', Meteor.default_connection._lastSessionId)
})

server/main.js

Meteor.methods({
    'active': function(uuid) {
        Active.insert({'uuid': uuid})
    }
})

You can't prevent the lastSessionId from changing because the server needs to have a record of the existing session in order to reconnect to it. In the case of a hot code reload the session would be cleared so it would assign a new session Id to the client.

What you could do is either store the new one as an entirely new session or just keep with the first session id as soon as you connect:

Meteor.startup(function() {
   Meteor.onConnection(function() {
      if(Session.equals("session_id", null)) Session.set("session_id", Meteor.default_connection._lastSessionId);
   });
   Meteor.call('active', Session.get("session_id"));
});

So this should survive a hot code push on the client, (since Session variables are preserved). For the case where the server has a hot code restart, the previous session_id would be used to insert stuff into your logs.