异步函数总是返回一个承诺。要查看承诺信息,您要么需要
await
如果在函数中,或使用
then()
如果你在全球范围内。
您的代码似乎在全局范围内,因此您需要使用一个then:
class Mongo {
async findDocuments(collection, query) {
var response = (await this.database.collection(collection).find(query)).toArray();
return response;
}
}
let mongo = new Mongo();
mongo.findDocuments('users', {}).then(result => {
console.log(result);
});