文中使用的mongoose基于 5.4.14
库名
var mongoose = require('mongoose');
//记得修改为你的服务器ip
mongoose.connect('mongodb://47.***.**.176:27017/admin', {useNewUrlParser: true},function(err,connection){
connection.db.admin().listDatabases().then(res=>{
var dbs = res.databases.map(function(base){
return base.name;
})
console.log(dbs);
}).catch(err=>{
console.log(err);
})
});
表名亦或者是collections
var mongoose = require('mongoose');
//记得修改为你的服务器ip 和 data_base_name 库名
mongoose.connect('mongodb://47.***.**.176:27017/data_base_name', {useNewUrlParser: true},function(err,connection){
connect.db.collections().then(res => {
var collections = res.map(function (collection) {
return collection.collectionName;
})
console.log(collections );
}).catch(err=>{
console.log(err);
})
});