mongo_indexes.md 2.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
These are the indexes each mongo db should have in order to perform well.
Each section states the collection name and then the indexes. To create an index,
you'll typically either use the mongohq type web interface or a standard terminal console.
If a terminal, this assumes you've logged in and gotten to the mongo prompt 
```
mongo mydatabasename
```

If using the terminal, to add an index to a collection, you'll need to prefix ```ensureIndex``` with
```
db.collection_name
```
as in ```db.location_map.ensureIndex({'course_id': 1}{background: true})```

15 16 17
fs.files:
=========

18 19
Index needed thru 'category' by `_get_all_content_for_course` and others. That query also takes a sort
which can be `uploadDate`, `display_name`, 
Don Mitchell committed
20

Don Mitchell committed
21
Replace existing index which leaves out `run` with this one:
22
```
23 24 25 26 27 28
ensureIndex({'_id.org': 1, '_id.course': 1, '_id.name': 1}, {'sparse': true})
ensureIndex({'content_son.org': 1, 'content_son.course': 1, 'content_son.name': 1}, {'sparse': true})
ensureIndex({'_id.org': 1, '_id.course': 1, 'uploadDate': 1}, {'sparse': true})
ensureIndex({'_id.org': 1, '_id.course': 1, 'display_name': 1}, {'sparse': true})
ensureIndex({'content_son.org': 1, 'content_son.course': 1, 'uploadDate': 1}, {'sparse': true})
ensureIndex({'content_son.org': 1, 'content_son.course': 1, 'display_name': 1}, {'sparse': true})
29
```
30 31 32 33 34 35 36 37 38 39 40 41

modulestore:
============

Mongo automatically indexes the ```_id``` field but as a whole. Thus, for queries against modulestore such
as ```modulestore.find({'_id': {'tag': 'i4x', 'org': 'myu', 'course': 'mycourse', 'category': 'problem', 'name': '221abc', 'revision': null}})```
where every field in the id is given in the same order as the field is stored in the record in the db
and no field is omitted.

Because we often query for some subset of the id, we define this index:

```
42
ensureIndex({'_id.org': 1, '_id.course': 1, '_id.category': 1, '_id.name': 1})
43 44 45 46 47 48 49
```

Because we often scan for all category='course' regardless of the value of the other fields:
```
ensureIndex({'_id.category': 1})
```

50 51
Because lms calls get_parent_locations frequently (for path generation):
```
52
ensureIndex({'definition.children': 1}, {'sparse': true})
53 54 55 56 57 58
```

modulestore.active_versions
===========================

```
59
ensureIndex({'org': 1, 'course': 1, 'run': 1}, {'unique': true})
60
```