Trung BìnhMongoDB iconMongoDB

MongoDB `explain` đọc như thế nào?

explain("executionStats") cho biết query dùng index nào, docs/keys examined, docs returned, stage tree và thời gian thực thi. Mục tiêu là keys/docs examined gần với số docs returned, không phải scan quá rộng.

Ví dụ:

javascript
db.orders.find({ tenantId: "t1", status: "paid" }).explain("executionStats")

Nếu thấy COLLSCAN, docs examined rất lớn hoặc sort in memory, cần xem lại index/query shape/projection.

Xem toàn bộ MongoDB cùng filter theo level & chủ đề con.

Mở danh sách MongoDB