ลบฐานข้อมูลทั้งหมดด้วย dropDatabase()
ใช้ฟังก์ชัน dropDatabase() เพื่อลบข้อมูลทั้งหมดในฐานข้อมูล MongoDB
use yourDatabaseName; db.dropDatabase();
ขั้นตอนการลบฐานข้อมูล
- แสดงรายการฐานข้อมูลทั้งหมดด้วย
show dbs - สลับไปใช้ฐานข้อมูลที่ต้องการลบด้วย
use databaseName - รันคำสั่ง
db.dropDatabase() - ตรวจสอบอีกครั้งด้วย
show dbs
ตัวอย่างการลบฐานข้อมูล 'flightInformation'
> use flighInformation; switched to db flighInformation > db.dropDatabase();
{ "dropped" : "flighInformation", "ok" : 1 }
ตรวจสอบผลลัพธ์
> show dbs;
admin 0.000GB config 0.000GB local 0.000GB sample 0.000GB sampleDemo 0.000GB test 0.003GB
ฐานข้อมูล 'flightInformation' ถูกลบออกจากรายการแล้ว