I want find many random records doing only 1 query.
I tried:
var count = db.collections.count()
var rand = function(){return Math.floor( Math.random() * count )}
db.collection.find().limit(-1).skip(rand()).next();
But this returns only one document. I need to get more random records.
How can I do this?
Another way to achive
db.Colletion.find().limit( 50 ).skip( _rand() * db.Collection.count() )
change the limit() as per your requirement, Hope this will Help....
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With