summaryrefslogtreecommitdiff
path: root/node_modules/mongoose/docs/indexes.md
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2012-09-24 16:22:07 -0400
committerJules Laplace <jules@okfoc.us>2012-09-24 16:22:07 -0400
commit686106d544ecc3b6ffd4db2b665d3bc879a58d8c (patch)
treea5b5e50237cef70e12f0745371896e96f5f6d578 /node_modules/mongoose/docs/indexes.md
ok
Diffstat (limited to 'node_modules/mongoose/docs/indexes.md')
-rw-r--r--node_modules/mongoose/docs/indexes.md43
1 files changed, 43 insertions, 0 deletions
diff --git a/node_modules/mongoose/docs/indexes.md b/node_modules/mongoose/docs/indexes.md
new file mode 100644
index 0000000..f294318
--- /dev/null
+++ b/node_modules/mongoose/docs/indexes.md
@@ -0,0 +1,43 @@
+
+Indexes
+=======
+
+Indexes are defined through `ensureIndex` every time a model is compiled for a
+certain connection / database. This means that indexes will only be ensured
+once during the lifetime of your app.
+
+## Definition
+
+Regular indexes:
+
+ var User = new Schema({
+ name: { type: String, index: true }
+ })
+
+[Sparse](http://www.mongodb.org/display/DOCS/Indexes#Indexes-SparseIndexes) indexes:
+
+ var User = new Schema({
+ name: { type: String, sparse: true }
+ })
+
+Unique indexes:
+
+ var User = new Schema({
+ name: { type: String, unique: true }
+ })
+
+ // or
+
+ var User = new Schema({
+ name: { type: String, index: { unique: true } }
+ })
+
+Unique sparse indexes:
+
+ var User = new Schema({
+ name: { type: String, unique: true, sparse: true }
+ })
+
+Compound indexes are defined on the `Schema` itself.
+
+ User.index({ first: 1, last: -1 }, { unique: true })