I had a similar problem. In my case, I had a date property in my docs. I knew the earliest date in the dataset, so in my application code I would generate a random date in the range of EARLIEST_DATE_IN_SET and NOW, and then query mongodb using the GTE query in the date property and just limit it to 1 result.
There was little chance that the random date would be greater than the highest date in the dataset, so I took this into account in the application code.
With the date property index, this was a quick request.
Bryan migliorisi
source share