I have a MongoDB collection, sorted by a field "a". Now, suppose I want to find the amount of objects in the collection for which the field "a" is between x and y. If I understand correctly, the way the naive query will be executed is simply iterating the array and checking all elements, which is O(n) complexity.
But since it is a sorted array, the operation is possible in O(log(n)). What is the fastest way to perform that query?