0

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;)?

JoshJoe
  • 1,482
  • 2
  • 17
  • 35
  • with my experience, some data that we should never removed them, just put a flag active/inactive. In this case why don't you just check `if(document)` or get data excludes the document. such as `db.find({ document: 0})`. Read more about `db.find({exclude: 0})` – Kai Oct 06 '14 at 02:50
  • I read the mongodb docs on exclude. I'm not sure how I would use exclude to remove the global id variable. Doesn't event emitter have some way of isolating each new event from the others? – JoshJoe Oct 08 '14 at 02:49
  • 3
    I'm unclear on what you're asking. Could you edit your question to add some code that illustrates what you're experiencing? – JohnnyHK Oct 16 '14 at 18:40

0 Answers0