I\'m aware that the Node driver for Mongo can be promisified using external libraries. I was curious to see if ES6 promises could be used with MongoClient.connect
There is nothing to get around, this is the expected behavior. cursor.count()
returns a promise, if you want the value, you need to use .then
, e.g.
DbConnection({}).then(
db => {
let cursor = db.collection('bar').find();
return cursor.count();
}
}).then(
count => {
console.log(count);
},
err => {
console.log(err);
}
);
or simplified
DbConnection({}).then(db => db.collection('bar').find().count()).then(
count => console.log(count),
err => console.log(err)
);