Blog

Xóa Collection trong MongoDB

Phương thức drop() trong MongoDB

Phương thức db.collection.drop() trong MongoDB được sử dụng để xóa một Collection từ cơ sở dữ liệu.

Cú pháp

Cú pháp cơ bản của lệnh drop() là như sau:

db.COLLECTION_NAME.drop()

Ví dụ

Đầu tiên, bạn kiểm tra các Collection có sẵn bên trong cơ sở dữ liệu mydb.

>use mydb switched to db mydb >show collections mycol mycollection system.indexes tutorialspoint >

Bây giờ, bạn xóa Collection với tên mycollection như sau:

>db.mycollection.drop() true >

Sau đó, kiểm tra lần nữa các Collection bên trong cơ sở dữ liệu:

>show collections mycol system.indexes tutorialspoint >

Phương thức drop() sẽ trả về true, nếu Collection đã chọn bị xóa thành công, nếu không, nó sẽ trả về false.

Leave a Reply

Your email address will not be published. Required fields are marked *

bujangjp slotsensa slot88 slot4d slot4d slot4d sv388 slot88 suhubet demo slot slot4d demo slot https://fabritec.pe/asesor.php suhubet bujangjp https://kibf.pk/ slotsensa buku303 slot4d sbobet slot gacor slot gacor slot gacor totogacor slot thailand slot thailand slot gacor slot luar negeri slot gacor 4d totogacor slot gacor wd jutaan slotsensa slot gacor slot gacor slotsensa slot gacor slot dana slot dana https://cliffcrestinn.com/ totogacor totogacor demo slot slot 4d totogacor totogacor demo slot totogacor slot thailand totogacor bujangjp situs gacor 4D situs gacor Situs Gacor 4D Thailand Situs Gacor 4D SLOT4D bujangjp