Introduction to MongoDB
1.0 - draft
1.0 - draft
  • MongoDB
  • Getting Started
    • General
      • Database? Collection? Schema?
      • RDBMS? NoSQL?
      • Scale-Up ? Scale - out?
      • JavaScript Object Notation
    • MongoDB
      • 간략한 역사,
    • Manipulating Database
      • MongoShell
      • PyMongo
  • CRUD
    • General
      • Explain()
      • mongoimport
    • Create
      • Mongo Shell
      • PyMongo
      • Exercises
    • Read
      • Mongo Shell
      • PyMongo
      • Exercises
    • Update
      • Mongo Shell
      • PyMongo
      • Exercises
    • Delete
      • PyMongo
      • Exercises
    • Challenging Exercises
      • Exercise 1
  • Index with Geospatial & Text
    • Basic Index
      • Syntax
      • Exercises
    • Geospatial Index
      • Syntax
      • Exercises
    • Text Index
      • Syntax
      • Exercises
    • Challenge
  • Aggregate framework
    • Aggregate Framework
      • Basic
      • Exercises
  • Distributed
    • Replication
      • Setup
        • Configuration File
        • Running Servers
        • Initiation
        • Exercises
      • Concerns
        • Read Concern
        • Write Concern
        • Exercises
    • Sharding
      • Getting Started
      • Setup
  • MongoDB 4.0 Features
    • Multi-Document Transaction
      • Transaction?
      • Basic
      • Exercises
  • Administration
    • Untitled
Powered by GitBook
On this page
  • Exercise 1
  • Exercise 2

Was this helpful?

  1. Index with Geospatial & Text
  2. Basic Index

Exercises

PreviousSyntaxNextGeospatial Index

Last updated 5 years ago

Was this helpful?

Exercise 1

  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}} 

  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",
    …
  3. 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}} 
  4. 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
      	}

😀