I am trying to create a two column unique index on the underlying mongodb in a meteor app and having trouble. I can\'t find anything in the meteor docs. I have tried from
Searching inside Meteor source code, I found a bind to ensureIndex called _ensureIndex
.
For single-key basic indexes you can follow the example of packages/accounts-base/accounts_server.js
that forces unique usernames on Meteor:
Meteor.users._ensureIndex('username', {unique: 1, sparse: 1});
For multi-key "compound" indexes:
Collection._ensureIndex({first_id:1, another_id:1}, {unique: 1});
The previous code, when placed on the server side, ensures that indexes are set.
Notice _ensureIndex implementation warning:
We'll actually design an index API later. For now, we just pass through to Mongo's, but make it synchronous.