Here is my collection which has more than 1 billion documents in it and each document has size of 2 KB
sample document
{
"sensor" : "temperature",
"timestamp" : ISODate("2018-02-22T01:55:00Z"),
... some more key values
}
I have index on key sensor and timestamp individualy Find query
db.collection.find({"sensor":"temperature", "timestamp":{"$gte":ISODate("2018-02-22T00:00:00Z"),
"$lt":ISODate("2018-02-23T00:00:00Z")}})
But it takes minutes to respond around more than 20-30 minutes which is not acceptable for my application. So what is the better way to optimize this query so it will results in less than 30 seconds (because mongoose will return timeout error if query is taking more than 30 seconds). Is there any solution for optimizing query except sharding?