- 节点和MongoDB教程
- 节点和MongoDB - 主页
- 节点和MongoDB - 概述
- 节点和MongoDB - 环境设置
- 节点和MongoDB示例
- 节点和MongoDB - 连接数据库
- 节点和MongoDB - 显示数据库
- 节点和MongoDB - 删除数据库
- 节点和MongoDB - 创建集合
- 节点和MongoDB - 删除集合
- 节点和MongoDB - 显示集合
- 节点和MongoDB - 插入文档
- 节点和MongoDB - 选择文档
- 节点和MongoDB - 更新文档
- 节点和MongoDB - 删除文档
- 节点和MongoDB - 嵌入式文档
- 节点和MongoDB - 限制记录
- 节点和MongoDB - 排序记录
- 节点和MongoDB有用资源
- 节点和MongoDB - 快速指南
- 节点和MongoDB - 有用资源
- 节点和MongoDB - 讨论
节点和MongoDB - 删除数据库
要删除数据库,可以使用database.drop()方法删除选定的数据库。
MongoClient.connect(url, function(error, client) {
// Connect to the database
const database = client.db('myDb');
// Drop the database
database.dropDatabase();
});
示例
尝试以下示例来删除mongodb数据库 −
将以下示例复制并粘贴为mongodb_example.js −
const MongoClient = require('mongodb').MongoClient;
// Prepare URL
const url = "mongodb://:27017/";
// make a connection to the database
MongoClient.connect(url, function(error, client) {
if (error) throw error;
console.log("Connected!");
// Connect to the database
const database = client.db('myDb');
// Drop the database
database.dropDatabase();
console.log("Database dropped!");
// close the connection
client.close();
});
输出
使用节点执行mysql_example.js脚本并验证输出。
node mongodb_example.js Connected! Database dropped!
广告