如何解决nodejs + mongodb 光标到文档
我尝试在数据库上运行 currentop,如下面的链接所示。
https://docs.mongodb.com/manual/reference/operator/aggregation/currentOp/
这是我的代码:
async function currentOp() {
let conn;
try {
conn = await MongoClient.connect(adminUri,{ useUnifiedTopology: true });
console.log('connected to admin database');
const cursor = await conn.db('admin').aggregate([
{ $currentOp: { allUsers: true } }
]);
console.log(cursor);
} catch (err) {
console.log(err);
} finally {
await conn.close();
}
}
currentOp();
但是,它打印光标信息,类似于
AggregationCursor {
_readableState: ReadableState { objectMode: true,highWaterMark: 16,buffer: BufferList { head: null,tail: null,length: 0 },length: 0,...
我想要实际的文档,而不是光标。我试过 cursor.toArray()
或 cursor.next()
但这会出错。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。