I’m using a timeseries collection to store trades of infrequently traded stocks.
The number of trades for each stock is between 1k to 30k and I’m using the stock ticker as the metadata field.
Sample document:
{
price: Number,
ticker: String,
timestamp: Date()
}
I’ve only created one secondary index on the metadata field(ticker) and the queries are very performant.
For example, when I want to get the $topN
orders based on price the responses I get are almost instantaneous even though .explain()
suggests that all the documents for that specific ticker are being examined. When I use a normal collection for the same data and indexes, the queries are much slower.
While creating an index on {ticker: 1, price: -1} and sorting documents based on the price reduces the totalDocsExamined
significantly, the query response times are not very different. So, I’m just wondering whether having secondary indexes is actually useful in this case or not? Does having them help when there’s more load on the database?