D
D
Dvorak2016-07-06 11:44:15
MongoDB
Dvorak, 2016-07-06 11:44:15

What is the best way to get rid of memory leaks in MongoDB?

Good day.
There are functions to add, overwrite and delete a user. They look something like this:

function addUser(db, user, collection) {
  db.open(function(err, db) {
    let users = db.collection(collection);
    users.insert(user, function(err, result) {
      db.close();
    });
  });
};

The rest of the functions look similar. After a large number of calls to such functions, a message about a memory leak appeared in the console. As I understand it, this happened due to the fact that each time db.open()an event handler is added. I solved this problem by adding the line db.s.topology.s.server._eventsCount = 1;.
There are no more leaks, but is it the right thing to do? Maybe there is a better way?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question