I've noticed some odd activity in my MongoDB collection and I believe that some events I've received back to back are sharing global variables.
For instance, I had a document that I removed prematurely from the collection, then I received an event that referenced this document. What seems to have happened is the id from the previous event was used for this removed event. So the event caused my code to store data in the document that was previously called.
My question is, how should I be cleaning up global variables after each event? It seems difficult to pinpoint how this could even be done since all of the event calls are being done async and the end event is called before I'm done using the global variables. Sometimes I might even have many events that come in before the others are completed.
Do I have to go back to using only local variables? (ones stored using var variable_name = data;
)?