我试图找到这个问题的解决方案:http://mongodb.github.io/node-mongodb-native/
但是,我找不到从Node.js应用程序列出所有可用MongoDB数据库的解决方案.
Joh*_*mez 11
您现在可以使用 Node Mongo 驱动程序执行此操作(使用 3.5 测试)
const MongoClient = require("mongodb").MongoClient;
const url = "mongodb://localhost:27017/";
const client = new MongoClient(url, { useUnifiedTopology: true }); // useUnifiedTopology removes a warning
// Connect
client
.connect()
.then(client =>
client
.db()
.admin()
.listDatabases() // Returns a promise that will resolve to the list of databases
)
.then(dbs => {
console.log("Mongo databases", dbs);
})
.finally(() => client.close()); // Closing after getting the data
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7546 次 |
| 最近记录: |