Why does mongodb affect the operation of generator in nodejs

  node.js, question

I used the generator in nodejs to operate mongodb in the project, but the experiment found that as long as mongodb’s connection is not closed, then even if generator’s done becomes true, the program will not exit. Please help me.

In the following code, as long as all db.close () are commented out, the generator’s done is true, but the program still does not exit.

var mongodb = require('mongodb');
 
 var db = null;
 
 function* DO(){
 try{
 db = yield connectMongodb();
 var collection = db.collection('userStruct');
 console.log('collection');
 var res = yield findSomething(collection, db);
 console.log('res', res);
 }catch(e){
 console.log('err', e);
 if(db){
 db.close();
 bracket
 bracket
 bracket
 
 var a = DO();
 console.log('first', a.next());
 
 function connectMongodb(){
 var mongoClient = mongodb.MongoClient;
 
 var DB_CONN_STR = 'mongodb://127.0.0.1:27017/jue';
 
 mongoClient.connect(DB_CONN_STR, function(err, db){
 if(err){
 a.throw(err);
 }else{
 console.log('connect', a.next(db));  bracket
 bracket
 })
 bracket
 
 function findSomething(collection, db){
 collection.find({test:1}).toArray(function(err, retArr){
 if(err){
 a.throw(err);
 }else{
 console.log('in find');
 db.close();
 console.log('find', a.next(retArr));
 bracket
 })
 bracket

yieldYou should take a promise in the back