I need to pull multiple random documents from a collection in MongoDB. I don’t want to ad a new key to my documents or use a map reduce. Any suggestions?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can generate random skip in range from 0 up to collection items count and then load documents:
But, such approach because less and less efficient for a big collections, because each time when you use skip mongodb iterate from first to skip item.