I have the following MongoDB schema:
mandate: {
type: mongo.Schema.Types.ObjectId,
ref: 'Mandate',
required: true
},
observer: {
type: mongo.Schema.Types.ObjectId,
ref: 'Observer',
required: true
},
value: {
type: Number,
required: true
},
observedAt: {
type: Date,
required: true
}
This collections holds an huge amount of data.
I ask for data in the following way: give me all data observerd between 2015 and 2016 where observer = "a" and mandate = "b"
Is there a best practise approach for a compound index over the 3 fields (observer, mandate, observedAt)?
For today, i do this like this:
schema.index({
mandate: 1,
observer: 1,
observedAt: -1
});
It this the right way?