I have a schema that looks something like ...
const itemSchema = new Schema({
sizes: [{
type: String,
enum: [/* some fixed sizes */],
}],
// other properties ...
});
I perform queries of the form Items.find({ sizes: { $elemMatch: 'someSize' } });
So I want to add index to those sizes inside of an element so the query is performed quickly.
Should it be something like:
const itemSchema = new Schema({
sizes: [{
type: String,
enum: [/* some fixed sizes */],
index: true,
}],
// other properties ...
});
or
const itemSchema = new Schema({
sizes: {
type: [{
type: String,
enum: [/* some fixed sizes */],
}],
index: true,
},
// other properties ...
});
or maybe a third option ?