When using the attribute pattern should I be mindful of the number of attributes I create per document to ensure good performance? And what impact does a larger number of attributes have on write and query performance?
My use case is that I would like my users to be able to filter data based on averages over the past number of years but balance this with maintaining good performance. Will there be a significant impact on performance between having 3 attributes and 12 attributes in an indexed field given the number of index keys increases?
Existing document (simplified version) - Yearly data
{
"name": "Product Name",
"price": {
"Avg365": 10,
"Avg730": 5,
"Avg1095": 15
}
}
Propose new document (simplified version) - Every 90-days
{
"name": "Product Name",
"price": {
"Avg90": 4,
"Avg180": 8,
"Avg270": 9,
"Avg365": 10,
"Avg455": 10,
"Avg545": 6,
"Avg635": 8,
"Avg730": 5,
"Avg820": 10,
"Avg910": 12,
"Avg1000": 18,
"Avg1095": 15
}
}
In these cases I have an index on “price” with queries such as:
{ price: {$elemMatch: { "k": "Avg365", "v": { $lte: 8, $gte: 1 } } } }