Properly close mongoose’s connection once you’re done

Properly close mongoose’s connection once you’re done

Asked on January 5, 2019 in MongoDB.
Add Comment


  • 3 Answer(s)

    We need to close the connection with

    mongoose.connection.close()
    
    Answered on January 5, 2019.
    Add Comment

    With the another solution is could n’t work, I had to use mongoose.disconnect();

     

    Answered on January 5, 2019.
    Add Comment

    When you disconnect the connection before you set the connection variable then when you are done

    var db = mongoose.connect('mongodb://localhost:27017/somedb');
    // Do some stuff
    db.disconnect()
    
    Answered on January 5, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.