You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 24, 2021. It is now read-only.
Copy file name to clipboardExpand all lines: source/api/collections.md
+14Lines changed: 14 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -394,6 +394,20 @@ Meteor.startup(() => {
394
394
});
395
395
```
396
396
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' });
0 commit comments