Hướng dẫn what is the fastest operation to clear an entire collection in mongodb? - thao tác nhanh nhất để xóa toàn bộ bộ sưu tập trong mongodb là gì?

Tài liệu về nhà → Hướng dẫn sử dụng MongoDBMongoDB Manual

Quan trọng

Phương pháp Dành cho Mongosh

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
4Remove tài liệu từ một bộ sưu tập.
Hướng dẫn what is the fastest operation to clear an entire collection in mongodb? - thao tác nhanh nhất để xóa toàn bộ bộ sưu tập trong mongodb là gì?

Removes documents from a collection.

Phương pháp

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
4 có thể có một trong hai cú pháp. Phương thức
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6 có thể lấy tài liệu truy vấn và
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
7 Boolean tùy chọn:
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
4
method can have one of two syntaxes. The
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6
method can take a query document and an optional
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
7 boolean:

db.collection.remove(
<query>,
<justOne>
)

Hoặc phương thức có thể lấy tài liệu truy vấn và tài liệu tùy chọn xóa tùy chọn:

Đã thay đổi trong phiên bản 5.0.

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)

Tham số

Loại hình

Sự mô tả

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
8

tài liệu

Chỉ định tiêu chí xóa bằng cách sử dụng các toán tử truy vấn. Để xóa tất cả các tài liệu trong một bộ sưu tập, hãy truyền một tài liệu trống (

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
9).

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
7

boolean

Không bắt buộc. Để giới hạn việc xóa chỉ một tài liệu, được đặt thành

collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
1. Bỏ qua để sử dụng giá trị mặc định của
collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
2 và xóa tất cả các tài liệu phù hợp với tiêu chí xóa.

collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
3

tài liệu

Chỉ định tiêu chí xóa bằng cách sử dụng các toán tử truy vấn. Để xóa tất cả các tài liệu trong một bộ sưu tập, hãy truyền một tài liệu trống (

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
9).Write Concern.

Không bắt buộc. Để giới hạn việc xóa chỉ một tài liệu, được đặt thành

collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
1. Bỏ qua để sử dụng giá trị mặc định của
collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
2 và xóa tất cả các tài liệu phù hợp với tiêu chí xóa.

collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
4

tài liệu

Optional.

Chỉ định tiêu chí xóa bằng cách sử dụng các toán tử truy vấn. Để xóa tất cả các tài liệu trong một bộ sưu tập, hãy truyền một tài liệu trống (

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
9).

Không bắt buộc. Để giới hạn việc xóa chỉ một tài liệu, được đặt thành

collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
1. Bỏ qua để sử dụng giá trị mặc định của
collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
2 và xóa tất cả các tài liệu phù hợp với tiêu chí xóa.

Không bắt buộc. Một tài liệu thể hiện mối quan tâm viết. Bỏ qua để sử dụng mối quan tâm ghi mặc định. Xem Viết mối quan tâm.

collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}

Không đặt rõ ràng mối quan tâm ghi cho hoạt động nếu chạy trong một giao dịch. Để sử dụng viết mối quan tâm với các giao dịch, xem giao dịch và viết mối quan tâm.

Chỉ định đối chiếu để sử dụng cho hoạt động.

Đối chiếu cho phép người dùng chỉ định các quy tắc cụ thể về ngôn ngữ để so sánh chuỗi, chẳng hạn như các quy tắc cho Lettercase và Dấu nhấn.

Tùy chọn đối chiếu có cú pháp sau:

let

tài liệu

Optional.

Chỉ định tiêu chí xóa bằng cách sử dụng các toán tử truy vấn. Để xóa tất cả các tài liệu trong một bộ sưu tập, hãy truyền một tài liệu trống (

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
9).

Không bắt buộc. Để giới hạn việc xóa chỉ một tài liệu, được đặt thành

collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
1. Bỏ qua để sử dụng giá trị mặc định của
collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
2 và xóa tất cả các tài liệu phù hợp với tiêu chí xóa.

{ <variable_name_1>: <expression_1>,
...,
<variable_name_n>: <expression_n> }

Không bắt buộc. Một tài liệu thể hiện mối quan tâm viết. Bỏ qua để sử dụng mối quan tâm ghi mặc định. Xem Viết mối quan tâm.

Không đặt rõ ràng mối quan tâm ghi cho hoạt động nếu chạy trong một giao dịch. Để sử dụng viết mối quan tâm với các giao dịch, xem giao dịch và viết mối quan tâm.

Chỉ định đối chiếu để sử dụng cho hoạt động.

Đối chiếu cho phép người dùng chỉ định các quy tắc cụ thể về ngôn ngữ để so sánh chuỗi, chẳng hạn như các quy tắc cho Lettercase và Dấu nhấn.

Tùy chọn đối chiếu có cú pháp sau:Use Variables in

{ <variable_name_1>: <expression_1>,
...,
<variable_name_n>: <expression_n> }
1

Khi chỉ định đối chiếu, trường

collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
5 là bắt buộc; Tất cả các trường đối chiếu khác là tùy chọn. Để biết mô tả của các trường, xem tài liệu đối chiếu.

Xác nhận bộ sưu tập để xóa. Trong hộp thoại, nhập tên của bộ sưu tập để xóa ..

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6 returns an object that contains the status of the operation.

Returns:Xác nhận bộ sưu tập để xóa. Trong hộp thoại, nhập tên của bộ sưu tập để xóa ..WriteResult object that contains the status of the operation.

Phương thức

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6 sử dụng lệnh
{ <variable_name_1>: <expression_1>,
...,
<variable_name_n>: <expression_n> }
5, sử dụng mối quan tâm ghi mặc định. Để chỉ định một mối quan tâm ghi khác nhau, bao gồm mối quan tâm ghi trong tham số tùy chọn.
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6
method uses the
{ <variable_name_1>: <expression_1>,
...,
<variable_name_n>: <expression_n> }
5 command, which uses the default write concern. To specify a different write concern, include the write concern in the options parameter.

Theo mặc định,

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6 xóa tất cả các tài liệu phù hợp với biểu thức
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
8. Chỉ định tùy chọn
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
7 để giới hạn hoạt động để xóa một tài liệu. Để xóa một tài liệu duy nhất được sắp xếp theo thứ tự được chỉ định, hãy sử dụng phương thức FindAndModify ().
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6
removes all documents that match the
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
8 expression. Specify the
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
7 option to limit the operation to removing a single document. To delete a single document sorted by a specified order, use the findAndModify() method.

Khi xóa nhiều tài liệu, thao tác xóa có thể xen kẽ với các hoạt động đọc và/hoặc ghi khác vào bộ sưu tập.

Bạn không thể sử dụng phương pháp

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6 với bộ sưu tập giới hạn.
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6
method with a capped collection.

Bạn không thể sử dụng phương thức

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6 trên bộ sưu tập chuỗi thời gian.
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6
method on a time series collection.

Tất cả các hoạt động

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6 cho bộ sưu tập Sharded chỉ định tùy chọn

db.products.remove( { qty: { $gt: 20 } } )

2 phải bao gồm khóa Shard hoặc trường

db.products.remove( { qty: { $gt: 20 } } )

3 trong đặc tả truy vấn.
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6
operations for a sharded collection that specify the

db.products.remove( { qty: { $gt: 20 } } )

2 option must include the shard key or the

db.products.remove( { qty: { $gt: 20 } } )

3 field in the query specification.

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6 Các hoạt động Chỉ định

db.products.remove( { qty: { $gt: 20 } } )

2 trong bộ sưu tập Sharded không chứa khóa Shard hoặc trường

db.products.remove( { qty: { $gt: 20 } } )

3 trả về lỗi. operations specifying

db.products.remove( { qty: { $gt: 20 } } )

2 in a sharded collection which do not contain either the shard key or the

db.products.remove( { qty: { $gt: 20 } } )

3 field return an error.

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
4 có thể được sử dụng bên trong các giao dịch đa tài liệu. can be used inside multi-document transactions.

Không đặt rõ ràng mối quan tâm ghi cho hoạt động nếu chạy trong một giao dịch. Để sử dụng viết mối quan tâm với các giao dịch, xem giao dịch và viết mối quan tâm.

Quan trọng

Trong hầu hết các trường hợp, giao dịch đa tài liệu phát sinh chi phí hiệu suất lớn hơn so với ghi tài liệu đơn lẻ và sự sẵn có của các giao dịch đa tài liệu không nên là một sự thay thế cho thiết kế lược đồ hiệu quả. Đối với nhiều kịch bản, mô hình dữ liệu được chuẩn hóa (tài liệu và mảng nhúng) sẽ tiếp tục tối ưu cho các trường hợp dữ liệu và sử dụng của bạn. Đó là, đối với nhiều kịch bản, mô hình hóa dữ liệu của bạn một cách thích hợp sẽ giảm thiểu nhu cầu cho các giao dịch đa tài liệu.

Để biết các cân nhắc sử dụng giao dịch bổ sung (như giới hạn thời gian chạy và giới hạn kích thước oplog), xem thêm các cân nhắc sản xuất.

Sau đây là các ví dụ về phương pháp

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6.
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6
method.

Để xóa tất cả các tài liệu trong một bộ sưu tập, hãy gọi phương thức

db.products.remove( { qty: { $gt: 20 } } )

9 bằng một tài liệu truy vấn trống
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
9. Hoạt động sau đây xóa tất cả các tài liệu khỏi bộ sưu tập BIOS:

db.products.remove( { qty: { $gt: 20 } } )

9
method with an empty query document
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
9. The following operation deletes all documents from the bios collection:

Hoạt động này không tương đương với phương pháp

db.products.remove(
{ qty: { $gt: 20 } },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)
1.

Để loại bỏ tất cả các tài liệu khỏi một bộ sưu tập, có thể hiệu quả hơn khi sử dụng phương thức

db.products.remove(
{ qty: { $gt: 20 } },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)
1 để bỏ toàn bộ bộ sưu tập, bao gồm các chỉ mục, sau đó tạo lại bộ sưu tập và xây dựng lại các chỉ mục.

Để xóa các tài liệu phù hợp với tiêu chí xóa, hãy gọi phương thức

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6 với tham số
db.products.remove(
{ qty: { $gt: 20 } },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)
4:
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6
method with the
db.products.remove(
{ qty: { $gt: 20 } },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)
4 parameter:

Hoạt động sau đây sẽ loại bỏ tất cả các tài liệu khỏi bộ sưu tập

db.products.remove(
{ qty: { $gt: 20 } },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)
5 trong đó
db.products.remove(
{ qty: { $gt: 20 } },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)
6 lớn hơn
db.products.remove(
{ qty: { $gt: 20 } },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)
7:

db.products.remove( { qty: { $gt: 20 } } )

Hoạt động sau đây cho một bộ bản sao sẽ loại bỏ tất cả các tài liệu khỏi bộ sưu tập

db.products.remove(
{ qty: { $gt: 20 } },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)
5 trong đó
db.products.remove(
{ qty: { $gt: 20 } },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)
6 lớn hơn
db.products.remove(
{ qty: { $gt: 20 } },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)
7 và chỉ định mối quan tâm ghi của

db.products.remove( { qty: { $gt: 20 } }, true )

1 với

db.products.remove( { qty: { $gt: 20 } }, true )

2 của 5000 mili giây. Hoạt động này hoặc trở lại sau khi viết tuyên truyền cho cả chính và một phụ, hoặc hết lần sau 5 giây.

db.products.remove(
{ qty: { $gt: 20 } },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)

Để xóa tài liệu đầu tiên phù hợp với tiêu chí xóa, hãy gọi phương thức

db.products.remove( { qty: { $gt: 20 } } )

9 với tiêu chí
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
8 và tham số
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
7 được đặt thành
collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
1 hoặc

db.products.remove( { qty: { $gt: 20 } }, true )

7.

db.products.remove( { qty: { $gt: 20 } } )

9
method with the
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
8 criteria and the
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
7 parameter set to
collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
1 or

db.products.remove( { qty: { $gt: 20 } }, true )

7.

Hoạt động sau đây sẽ loại bỏ tài liệu đầu tiên khỏi bộ sưu tập

db.products.remove(
{ qty: { $gt: 20 } },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)
5 trong đó
db.products.remove(
{ qty: { $gt: 20 } },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)
6 lớn hơn
db.products.remove(
{ qty: { $gt: 20 } },
{ writeConcern: { w: "majority", wtimeout: 5000 } }
)
7:

db.products.remove( { qty: { $gt: 20 } }, true )

Đối chiếu cho phép người dùng chỉ định các quy tắc cụ thể về ngôn ngữ để so sánh chuỗi, chẳng hạn như các quy tắc cho Lettercase và Dấu nhấn.

Bộ sưu tập

{ _id: 1, category: "café", status: "A" }
{ _id: 2, category: "cafe", status: "a" }
{ _id: 3, category: "cafE", status: "a" }
1 có các tài liệu sau:

{ _id: 1, category: "café", status: "A" }
{ _id: 2, category: "cafe", status: "a" }
{ _id: 3, category: "cafE", status: "a" }

Hoạt động sau bao gồm tùy chọn đối chiếu:

db.myColl.remove(
{ category: "cafe", status: "A" },
{ collation: { locale: "fr", strength: 1 } }
)

Mới trong phiên bản 5.0.

Để xác định các biến mà bạn có thể truy cập ở nơi khác trong lệnh, hãy sử dụng tùy chọn LET.let option.

Ghi chú

Để lọc kết quả bằng cách sử dụng một biến, bạn phải truy cập biến trong toán tử

{ <variable_name_1>: <expression_1>,
...,
<variable_name_n>: <expression_n> }
0.

Tạo bộ sưu tập

{ _id: 1, category: "café", status: "A" }
{ _id: 2, category: "cafe", status: "a" }
{ _id: 3, category: "cafE", status: "a" }
3:

db.cakeFlavors.insertMany( [
{ _id: 1, flavor: "chocolate" },
{ _id: 2, flavor: "strawberry" },
{ _id: 3, flavor: "cherry" }
] )

Ví dụ sau đây xác định biến

{ _id: 1, category: "café", status: "A" }
{ _id: 2, category: "cafe", status: "a" }
{ _id: 3, category: "cafE", status: "a" }
4 trong
{ <variable_name_1>: <expression_1>,
...,
<variable_name_n>: <expression_n> }
1 và sử dụng biến để xóa hương vị bánh dâu tây:

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
0

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6 trả về một đối tượng
{ _id: 1, category: "café", status: "A" }
{ _id: 2, category: "cafe", status: "a" }
{ _id: 3, category: "cafE", status: "a" }
7 chứa trạng thái của hoạt động. Khi thành công, đối tượng
{ _id: 1, category: "café", status: "A" }
{ _id: 2, category: "cafe", status: "a" }
{ _id: 3, category: "cafE", status: "a" }
7 chứa thông tin về số lượng tài liệu bị xóa:
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6
returns a
{ _id: 1, category: "café", status: "A" }
{ _id: 2, category: "cafe", status: "a" }
{ _id: 3, category: "cafE", status: "a" }
7 object that contains the status of the operation. Upon success, the
{ _id: 1, category: "café", status: "A" }
{ _id: 2, category: "cafe", status: "a" }
{ _id: 3, category: "cafE", status: "a" }
7 object contains information on the number of documents removed:

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
1

Mẹo

Xem thêm:

Nếu phương thức

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6 gặp phải viết các lỗi liên quan, kết quả bao gồm trường
db.myColl.remove(
{ category: "cafe", status: "A" },
{ collation: { locale: "fr", strength: 1 } }
)
0:
db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6
method encounters write concern errors, the results include the
db.myColl.remove(
{ category: "cafe", status: "A" },
{ collation: { locale: "fr", strength: 1 } }
)
0 field:

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
2

Mẹo

Xem thêm:

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
6 method encounters a non-write concern error, the results include
db.myColl.remove(
{ category: "cafe", status: "A" },
{ collation: { locale: "fr", strength: 1 } }
)
2 field:

db.collection.remove(
<query>,
{
justOne: <boolean>,
writeConcern: <document>,
collation: <document>,
let: <document> // Added in MongoDB 5.0
}
)
3

Mẹo

Xem thêm:

Làm cách nào để xóa toàn bộ bộ sưu tập trong MongoDB?

Để xóa một bộ sưu tập MongoDB, hãy sử dụng lệnh db.collection.drop ().use db. collection. drop() command.

Phương pháp nào được sử dụng để xóa một bộ sưu tập trong MongoDB?

Để xóa tất cả các tài liệu khỏi một bộ sưu tập, hãy chuyển một tài liệu bộ lọc trống {} cho DB.thu thập.Phương thức deletemany ().

Làm thế nào để bạn làm trống một bộ sưu tập trong La bàn MongoDB?

Thả một bộ sưu tập..
Nhấp vào biểu tượng thùng rác để xóa bộ sưu tập.Từ màn hình Bộ sưu tập, nhấp vào thùng rác cho bộ sưu tập để xóa.Một hộp thoại xác nhận xuất hiện ..
Xác nhận bộ sưu tập để xóa.Trong hộp thoại, nhập tên của bộ sưu tập để xóa ..
Nhấp vào Drop Collection để thả bộ sưu tập ..