Exercises
Exercise 1
Create an index in ascending order for the writer field and get the index information. 😀
{'_id_': {'key': [('_id', 1)], 'ns': 'lab6.blog', 'v': 2}, 'writer_1': {'key': [('writer', 1)], 'ns': 'lab6.blog', 'v': 2}}
Again, print a query plan using executionStats corresponding to the query that finds a writer, Kim.
"executionStats" : { … "executionTimeMillis" : 0, "totalKeysExamined" : 1, "totalDocsExamined" : 1, "nReturned": 1, "executionStages": { "inputStage": { "stage": "IXSCAN", …
Create the compound index on id in descending order and writer in ascending order.
{'_id_': {'key': [('_id', 1)], 'ns': 'lab6.blog', 'v': 2}, 'id_-1_writer_1': {'key': [('id', -1), ('writer', 1)], 'ns': 'lab6.blog', 'v': 2}, 'writer_1': {'key': [('writer', 1)], 'ns': 'lab6.blog', 'v': 2}}
Drop all indexes on the blog collection.
{'_id_': {'key': [('_id', 1)], 'ns': 'lab6.blog', 'v': 2}}
Exercise 2
Index 생성
Create a unique index to doc_id in ascending order
Try to build a unique index to line_num
Create a sparse index to intersect in ascending order
Create a unique and sparse index to intersect_id in ascending order
Check the index information
Compare the results below two cases. (metro collection)
Show the first two documents, sorting with doc_id in ascending order.
Using intersect index by hint(), show the first two documents
Sort doc_id in ascending order
Use explain() above each case (executionStats).
No Index
"executionStats" : { … 'executionTimeMillis': 155, 'nReturned': 2, 'totalDocsExamined': 186024, 'totalKeysExamined': 0 }
Indexed
"executionStats" : { … 'executionTimeMillis': 21, 'nReturned': 2, 'totalDocsExamined': 2, 'totalKeysExamined': 2 }
Last updated
Was this helpful?