Y
Y
yvetrov2019-07-12 17:50:47
MongoDB
yvetrov, 2019-07-12 17:50:47

How to communicate with MongoDB?

I have an application, in it - registration. The data is collected, then simply transferred to MongoDB using mongoose. However, I ran into a problem: the appearance of new records causes the previous one to be overwritten. I quickly solved this problem by disconnecting from the database with mongoose.disconnect(); After that he writes to me:

Topology was destroyed.

How to solve the problem so that records in MongoDB are added, not overwritten, and all this without closing the connection?
Here is the code to send to the server:
user.password = hash;
    user.login = req.body.login;
    user.save(function(err){
      mongoose.disconnect();

      if(err) return console.log(err);
    });

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