Devdit
 

Python MongoDB ลบฐานข้อมูล

590

Python MongoDB ลบฐานข้อมูล บทความนี้สอนใช้คำสั่ง drop_database เพื่อลบฐานข้อมูล (Databases) จาก MongoDB ด้วยภาษา Python โดยใช้ module pymongo พร้อมแสดงผลลัพธ์ออกสู่หน้าจอ สามารถเขียนโปรแกรมได้ดังนี้

 

ตัวอย่าง Python MongoDB ลบฐานข้อมูล

from pymongo import MongoClient

conn = "mongodb://localhost:27017/"
client = MongoClient(conn)
client.drop_database('demo')
print('Python MongoDB ลบ Database เรียบร้อย')

ผลลัพธ์

Python MongoDB ลบ Database เรียบร้อย

คำอธิบาย

Python MongoDB ลบฐานข้อมูล จากตัวอย่างใช้คำสั่ง drop_database เพื่อลบฐานข้อมูลชื่อ demo จาก MongoDB ด้วยภาษา Python พร้อมแสดงผลลัพธ์ออกสู่หน้าจอด้วยคำสั่ง print

เขียน 1 ปีที่แล้ว
ชอบ
ลิ้งก์
แชร์
Devdit มีช่อง YouTube แล้ว
เราสร้างวิดีโอเกี่ยวกับเทคโนโลยี ทำตามง่ายๆ