I am creating a collection in mongodb, and it's going to contain 1Tera of entities. Queries on it currently demand 5 compound indexes on this collection.
I know too many indexes is not recommended but this collection has some frequent queries that must be indexed.
There's one case where I'm contemplating how to model my data and indexes:
In the documents there can be two types of parents. PARENTA and PARENTB. queries are for each type separately.
I have two options:
1. save 2 fields for the 2 parents types and have an index for each field
{
parentsA: ['parentA1', 'parentA2']
parentsB: ['parentB1]
}
- save 1 field which will include the type, and one index for it:
{
parents: [
{parentType: 'PARENTA', parentId: 'parentA1'},
{parentType: 'PARENTA', parentId: 'parentA2'},
{parentType: 'PARENTB', parentId: 'parentB1'}
]
}
and then when I filter I also add the type (PARENTA / PARENTB).
Is solution 2 more efficient because I need 1 index instead of 2? (Considering I already have 5 other compound indexes).