-
Notifications
You must be signed in to change notification settings - Fork 3
3.0 Indexing
this page will be about indexing

Indexes improve query execution by storing a portion of the collection in a small B-tree collection that can be searched quickly, and saves query execution time by avoiding collection scan where all records in the collection are scanned.
The process of building indices heavily impacts the database and prevents read and write operations. To avoid this impact index construction can be run in the background using Background Construction.
Indexes can be created in embedded fields as well as embedded documents. An index on an embedded field can be created using a dot notation on a top level field and will support queries that search embedded document fields.
db.<abstract_collection>.createIndex( { "location.city":1 } )
An index on an embedded document indexes the entire document and returns results that match exactly, including all the fields and the order.
examples: https://docs.mongodb.com/manual/core/index-single/
Indexing replica sets involves stopping updates and indexing each replica at a time. I sharded clusters this process need to be repeated for each shard.
- Stop a secondary and restart as standalone
- Build index
- Restart mongod as part of replica set/shard
- Wait for restarted secondary to catch up on replication
- Repeat for remaining members
- Restart former primary as standalone
- Build index
- restart mongodb as part of replica set/shard
- Wait for replication to catch up
More info here https://docs.mongodb.com/manual/tutorial/build-indexes-on-replica-sets/#index-building-replica-sets
GS1 Canada® is a registered trademark of GS1 Canada. Copyright © GS1 Canada 2018.