Inital Commit
[oweals/finalsclub.git] / node_modules / mongoose / docs / indexes.md
1
2 Indexes
3 =======
4
5 Indexes are defined through `ensureIndex` every time a model is compiled for a
6 certain connection / database. This means that indexes will only be ensured
7 once during the lifetime of your app.
8
9 ## Definition
10
11 Regular indexes:
12
13     var User = new Schema({
14         name: { type: String, index: true }
15     })
16
17 Unique indexes:
18
19     var User = new Schema({
20         name: { type: String, unique: true }
21     })
22
23     // or 
24
25     var User = new Schema({
26         name: { type: String, index: { unique: true } }
27     })
28
29 Compound indexes are defined on the `Schema`
30
31     User.index({ first: 1, last: -1 })