I have a requests table within my database which consists of a few fields such as "pending" to denote if a request has not been serviced, "expiry" to keep a track of the expiry time in milliseconds (Epoch), "count" which counts down to 0 every time the request is fired.
Now I search for all requests where either the request has expired OR the count has dropped to 0 AND pending is true. I am then ordering the results based on the expiry time.
I did try to create an index for this but based on the results for my explain() command, I am sure MongoDB is not using the index. Any suggestions on what should be the compound index for such a query ?
To put it in generic terms, the query is essentially (A OR B) AND C ordered by C
That's the query I built via Morphia, Java (I am new to MongoDB) ->
query.and(query.criteria("pending").equal(true));
query.or(query.criteria("count").equal(0), query.criteria("expiry").lessThan(System.currentTimeMillis()));
query.order("expiry");