Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compound indexes #1

Open
selaias opened this issue Dec 16, 2015 · 2 comments
Open

compound indexes #1

selaias opened this issue Dec 16, 2015 · 2 comments

Comments

@selaias
Copy link

selaias commented Dec 16, 2015

great idea in including indexing options at field level.
Although it will serve every day needs, I wonder how this could be extended to manage compound indexes and Index intersection for more advanced apps that aim to use covered queries for better performance.
I guess it should be at collection level?

@Ragsboss
Copy link

+1, we also have a need to define compound unique key. For example, fields 'foo' and 'bar' are both non-optional and we want the combination to be unique.

@dpankros
Copy link

or perhaps specify the name of the index on each field and then define the index at the collection level, including the same name. E.g.

Schema = new SimpleSchema {
 compoundField1: {
  type: Number,
  name: 'Compound Field 1',
  index: 'compound_index_1'
},
compoundField2: {
  type: Number,
  name: 'Compound Field 2',
  index: ['compound_index_1', 'index2'] //<-- note MULTIPLE indexes on the same field
}
...
}
Collection = new Mongo.Collection('collection');
Collection.attachSchema(Schema);
Collection.attachIndex('compound_index_1', {
  unique: true,
  background: false,
  //sparse: false,
  //partialFilterExpression: xxx
  //expireAfterSeconds: xxx
  //storageEngine: xxx
  //and so on
  //basically all the mongo properties could be passed through to createIndex
});
Collection.attachIndex('index2'); //just use the deafults.  e.g. simple, ascending index

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants