'Is it possible to change the default order of a MongoDB collection to something more random?

I need to process a collections of about 10M items

The problem is that the oldest items are coming out first when I do a find, and those items have more data so they take a lot longer to process, and that's problematic because I rely on some API that will timeout if the group of items I send is too large to process.

I'd like to have a mix of old and new items when I do a find, is it possible without fetching the whole DB each time I run my script and shuffling it?

how can I easily do this? thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source