I want to retrieve 'N' (lets say 15 records) random records from particular collection. How can I get this? Please help me. Its very urgent.
Here's as close as I can think of...use localvar n = db.oplog.rs.count();var s = Math.floor(Math.random() * n);db.oplog.rs.find().skip(s).limit(15);There's number of things wrong with this... Start is random but next 15 records are returned in natural order. It's also possible to get less than 15 depending on skip point. Other than making 15 separate calls I'm not sure there's anything better.
Rhys