title: mongoose.connection.close() or mongoose.disconnect() takes ~10-12 seconds before the connection actually closes
body: <pre><code>const mongoose = require(&quot;mongoose&quot;);
  
  mongoose.connect(&quot;mongodb://localhost:27017/fruitsDB&quot;, {
    useNewUrlParser: true
  });
  
  const fruitSchema = new mongoose.Schema({
    name: String,
    rating: Number,
    review: String
  });
  const Fruit = mongoose.model(&quot;Fruit&quot;, fruitSchema);
  
  const fruit = new Fruit({
    name: &quot;Apple&quot;,
    rating: 7,
    review: &quot;Good Fruit&quot;
  });
  fruit.save();
  
  const banana = new Fruit({
    name: &quot;banana&quot;,
    rating: 9,
    review: &quot;Noice&quot;
  });
  
  const mango = new Fruit({
    name: &quot;Mango&quot;,
    rating: 10,
    review: &quot;best Fruit&quot;
  });
  
  Fruit.insertMany([banana, mango], function (err) {
    if (err) console.log(err);
    else console.log(&quot;Inserted all!&quot;);
  });
  
  Fruit.find(function (err, fruits) {
    if (err) console.log(err);
    else {
      mongoose.connection.close();
      fruits.forEach((fruitdata) =&gt; {
        console.log(fruitdata.name);
      });
    }
  });
  </code></pre>
  <p>The mongoose.connection.close() takes almost 10-12 seconds to before the connection actually closes. I have also tried mongoose.disconnect() but the problem still persists. Using the async function and await key also made no differnce.
  I don't know what is going wrong. But from my understanding in the following snippet the error handling is taking time.</p>
  <pre><code>Fruit.find(function (err, fruits) {
    if (err) console.log(err);
    else {
      mongoose.connection.close();
      fruits.forEach((fruitdata) =&gt; {
        console.log(fruitdata.name);
      });
    }
  });
  </code></pre>
  <p>If i just place the mongoose.connection.close() or mongoose.disconnect() above this snippet, the connection is closed in milli secs but when placed inside the .find's callback function it takes 10-12 seconds.</p>