Answer the question
In order to leave comments, you need to log in
How to select from a MongoDB collection of N random documents?
Faced the task of searching for N random documents in a MongoDB collection (with additional conditions on the fields).
1) Calling findOne N times on a pre-created random field is not a very optimal option
2) Using skip is not an option, since only the offset will be random here.
I found this option in the documentation
https://docs.mongodb.com/manual/reference/operator. ..
But the MongoDB driver for Java (spring-data-mongodb) specifically does not have this operator
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question