การดำเนินการที่ถูกจัดว่าเป็น "command" ใน MongoDB Profiler
ใน MongoDB Profiler การดำเนินการต่อไปนี้ถูกจัดประเภทเป็น "command" operation:
- count - นับจำนวนเอกสาร
- findAndModify - ค้นหาและแก้ไขแบบ atomic
- aggregate - aggregation pipeline
ตัวอย่าง count operation
> db.demo443.insertOne({ "Name": "Chris" });
> db.demo443.insertOne({ "Name": "Bob" });
> db.demo443.insertOne({ "Name": "David" });
ใช้ count()
> db.demo443.count();
3
ข้อมูลเพิ่มเติม
การดำเนินการ "command" จะปรากฏใน profiler output เมื่อเปิด profiling level 1 หรือ 2 สามารถดูได้จาก:
db.setProfilingLevel(1); // log slow operations (>100ms)
db.setProfilingLevel(2); // log all operations
จากนั้นตรวจสอบ:
db.system.profile.find({ op: "command" }).pretty();
คำสั่ง command อื่นๆ ที่พบบ่อย
- createIndexes, dropIndexes
- createCollection, dropCollection
- collStats, dbStats
- findAndModify (upsert)
- mapReduce
ประโยชน์
การรู้ว่า operation ใดเป็น command ช่วยในการ debug performance, ตั้งค่า slowms ให้เหมาะสม และวิเคราะห์ workload ของระบบ