Properly close mongoose's connection once you're done

后端 未结 7 758
没有蜡笔的小新
没有蜡笔的小新 2020-12-07 17:20

I\'m using mongoose in a script that is not meant to run continuously, and I\'m facing what seems to be a very simple issue yet I can\'t find an answer; simply put once I ma

7条回答
  •  -上瘾入骨i
    2020-12-07 17:37

    I'm using version 4.4.2 and none of the other answers worked for me. But adding useMongoClient to the options and putting it into a variable that you call close on seemed to work.

    var db = mongoose.connect('mongodb://localhost:27017/somedb', { useMongoClient: true })
    
    //do stuff
    
    db.close()
    

提交回复
热议问题