Do I need to manually close a mongoose connection?

前端 未结 3 1379
别那么骄傲
别那么骄傲 2020-12-15 20:20

New to Node, Mongoose & Mongodb - haven\'t read the source code...

I have a Node application which opens a file, parses the lines into records and saves the reco

3条回答
  •  遥遥无期
    2020-12-15 20:51

    You do need to call mongoose.disconnect() to close the connection, but you also need to wait until all save calls have completed their async work (i.e. called their callback) before doing that.

    So either keep a simple count of how many are still outstanding to keep track or use a flow control framework like async to do something a bit more elegant.

提交回复
热议问题