I have a collection with about 500000 dataset in it and I like to find a random dataset out of it. I can restrict the find() to the customer-id, which reduces the size to about 80000 sets. Indices are also added to the customer-id.
In PHP I use the following command to get the random dataset:
$mongoCursor = $mongoCollection->find($arrQuery, $arrFields)->skip(rand(1, $dataCount));
The profiler now tells:
DB.Collection ntoskip:3224 nscanned:3326 nreturned:101 reslen:77979 262ms
This takes quite some time to fetch the result. Is there a better way to get the data?
I thought about fetching all ids in PHP, then randomly take one id and find the complete set for this id. But I worry about fetching so many data in php.
Thanks for any thought on that topic. Dan