网上普遍说的listCollections没试成功
大概是这么写:
async function getColNames(){
await mgsCollection(); //open了才有mongoose.connection.db
let cols=await mongoose.connection.db.collections();
let colStrArr=[];
for(let c of cols){
colStrArr.push(c.s.name);
}
return colStrArr;
}
function mgsCollection(){
return new Promise((res,rej)=>{
mongoose.connection.on('open',function(){
res();
});
})
}