Answer the question
In order to leave comments, you need to log in
MongoDB random 2 entries?
Good evening!
The question arose, how to randomly select 2 records from many in MongoDB?
In SQL I would do this:SELECT * FROM sometable ORDER BY RAND() LIMIT 2
Answer the question
In order to leave comments, you need to log in
collection.find().limit(1).skip(yourRandomNumber).next()
yourRandomNumber <= size_of(collection)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question