Node program with promises does not end

I cannot understand for life why this does not end:

var pmongo = require('promised-mongo');
var db = pmongo('mongodb://localhost/builder');
var block_id = '538d097bbb12479d0e9f70ab';

var collection = db.collection('block');
collection.findOne({_id:db.ObjectId(block_id)})
.then(function(result) {
    console.dir(result);
}).done();

It just freezes. findOne returns the promise I'm calling. Oddly enough, when I close the database (i.e. Db.close ()) at that, it ends.

I try to end up doing this with express, so I really don't want to close the database. What trick ????

+4
source share
1 answer

MongoDB connections must be persistent. You create one of them (or their pool) and then reuse this connection in your application.

node.js, , node, . , , MySQL.

express.js , , .

+5

Source: https://habr.com/ru/post/1543277/


All Articles