MongoDB
 SQL >> Database >  >> NoSQL >> MongoDB

Usare le promise ES6 native con MongoDB

Non c'è nulla da aggirare, questo è il comportamento previsto. cursor.count() restituisce una promise; se vuoi il valore, devi usare .then, ad es.

DbConnection({}).then( db => { let cursor = db.collection('bar').find(); return cursor.count(); } ).then( count => { console.log(count); }, err => { console.log(err); } ); 

oppure in forma semplificata

DbConnection({}).then(db => db.collection('bar').find().count()).then( count => console.log(count), err => console.log(err) );