How to choose a MongoDB collection of N random documents?

Faced with the task of finding N random documents in a MongoDB collection (with additional fields).
1) Call findOne N times on a pre-established random field not too best option
2) Use skip is not an option, as there will only be a random offset

Found in the documentation of this option
https://docs.mongodb.com/manual/reference/operator...
But in the MongoDB driver for Java (spring-data-mongodb), this particular operator is not
July 8th 19 at 11:12
1 answer
July 8th 19 at 11:14
Solution

Find more questions by tags JavaMongoDBNoSQLSpring