Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> MongoDB

Cách xóa (drop) collection trong MongoDB

Để xóa collection, dùng lệnh drop(). Cú pháp:

db.yourCollectionName.drop();

Trả về true nếu thành công, false nếu thất bại.

Liệt kê collection trong database sample:

> use sample; switched to db sample
> show collections;
bookInformation userInformation

Xóa collection bookInformation:

> db.bookInformation.drop();
true

Kiểm tra lại:

> show collections;
userInformation

Collection bookInformation đã không còn tồn tại.