flimflam57
flimflam57

Reputation: 1334

Mongo indexing in Meteor

Not sure I'm understanding indexing mongo queries in Meteor. Right now, none of my queries are indexed. On some of the pages in the app, there are 15 or 20 links that instigate to a unique mongo query. Would each query be indexed individually?

For example, if one of the queries is something like:

 Template.myTemplate.helpers({
 ...
 if (weekly === "1") {
   var firstWeekers = _.where(progDocs, {Week1: "1"}),
   firstWeekNames = firstWeekers.map(function (doc) {
    return doc.FullName;
 });
 return Demographic.find({ FullName: { $in: firstWeekNames }}, { sort: { FullName: 1 }});
 }
 ...
 })

How would I implement each of the indexes?

Upvotes: 1

Views: 1624

Answers (1)

Michel Floyd
Michel Floyd

Reputation: 20226

Firstly minimongo (mongo on the client-side) runs in memory so indexing is much less of a factor than on disk. To minimize network consumption you also generally want to keep your collections on the client fairly small making indexing on the client-side even less important.

On the server however indexing can be critical to good performance. There are two common methods to setup indexes on the server:

  1. via the meteor mongo shell, i.e. db.demographic.createIndex( { FullName: 1 } )
  2. via setting the field to be indexed in your schema when using the Collection2 package. See aldeed:schema-index

Upvotes: 2

Related Questions