Skip to content
This repository was archived by the owner on Oct 24, 2021. It is now read-only.

Commit 1929ebd

Browse files
Merge pull request #742 from meteor/feature/createIndex
Document createIndex
2 parents 5079363 + 6740ee2 commit 1929ebd

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
title: Meteor API Docs
22
subtitle: API Docs
33
versions:
4+
- '2.4'
45
- '2.3'
56
- '2.2'
67
- '2.1'

code

Submodule code updated 200 files

source/api/collections.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,20 @@ Meteor.startup(() => {
394394
});
395395
```
396396

397+
{% apibox "Mongo.Collection#createIndex" %}
398+
399+
For efficient and performant queries you will sometimes need to define indexes other than the default `_id` field.
400+
You should add indexes to fields (or combinations of fields) you use to lookup documents in a collection.
401+
This is where `createIndex` comes into play. It takes in 2 objects. First is the key and index type specification (which field and how they should be indexed) and second are options like the index name.
402+
For details on how indexes work read the [MongoDB documentation](https://docs.mongodb.com/manual/indexes/).
403+
404+
> Note that indexes only apply to server and MongoDB collection. They are not implemented for Minimongo at this time.
405+
406+
Example defining a simple index on Players collection in Meteor:
407+
```js
408+
Players.createIndex({ userId: 1 }, { name: 'user reference on players' });
409+
```
410+
397411
{% apibox "Mongo.Collection#allow" %}
398412

399413
{% pullquote warning %}

0 commit comments

Comments
 (0)