225500
//获取数据中所有的集合
router.get("/listAllCollections", async (ctx, next) => {
let {query} = ctx;
const url = 'mongodb://'+query.host+':'+query.port;
const dbName = query.dbName;
await MongoClient.connect(url).then(async (client, err) => {
const db = client.db(dbName);
await db.listCollections().toArray().then((docs) => {
return ctx.body = {
statusCode: 200,
msg: "获取成功",
data: docs
}
}, (err) => {
console.log(err);
return ctx.body = {
statusCode: 403,
msg: "数据库错误"
}
})
})
});
db.listCollections() 官方文档 上写的是返回一个 command cursor ,虽然能用了 但是不太明白如何更好的理解这个东西 。