Mongoose Trying to open unclosed connection

前端 未结 6 448
离开以前
离开以前 2020-12-24 05:38

This is a simplified version of the problem, but basically I\'m trying to open 2 mongodb connections with mongoose and it\'s giving me \"Trying to open unclosed connection.\

6条回答
  •  無奈伤痛
    2020-12-24 06:14

    Using mongoose.disconnect(fn):

    mongoose.disconnect(() => {
    
      // here it would be possible "reset" models to fix 
      // OverwriteModelError errors
      mongoose.models = {};
    
      // here comes your logic like registering Hapi plugins
      server.register(somePlugin, callback);
    });
    

    I found this question typing the error message and despite my problem is a bit different I believe it could be useful for those using Hapi. More specifically Hapi + rest-hapi + mocha.

    When running mocha with --watch option I was facing both: OverwriteModelError and Error: Trying to open unclosed connection errors.

提交回复
热议问题