จุดเด่น
.
) ในการทำ index field จาก document ย่อย (subdocuments)db.<collection>.createIndex({ <field>: <direction> })
ดูขั้นตอนการ import ข้อมูลได้ที่นี่
อย่าลืมคำสั่ง use nfmongop
นะ
db.people.find({"ssn": "720-38-5636"}).explain("executionStats")
สังเกตว่ามีการใช้คำสั่ง .explain("executionStats")
ด้วย
db.people.createIndex({ ssn: 1 })
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
find()
อีกครั้งwinningPlan > inputStage > stage: IXSCAN
จากนั้นลองรันคำสั่ง find()
ใน field อื่น เช่น .find({ last_name: "Acevedo" })
และสังเกตค่า winningPlan กับ executionStats
db.<collection>.createIndex({ field.subfield: 1 })
db.people.find({'snn': { $gte: '000-00-0000', $lt: '556-00-0000' }}).explain("executionStats")
db.people.find({"ssn": { $in: ["720-38-5636","008-74-2203"]}}).explain("executionStats")
และสังเกตค่า winningPlan กับ executionStats จะเห็นว่าค่า totalKeysExaminded มีจำนวนที่มากกว่า nReturned ซึ่งถือว่าพอรับได้
ส่วนนี้ขึ้นอยู่กับ Algorithm ด้วยครับ