Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I am looking to get a random record from a huge (100 million record) mongodb.

What is the fastest and most efficient way to do so? The data is already there and there is no field in which I can generate a random number and obtain a random row.

Any suggestions?

1 Answer

0 votes
by (106k points)
To know about the random record from MongoDB you can count all records and generate a random number between 0 and the count, and then do:

db.yourCollection.find().limit(-1).skip(yourRandomNumber).next()

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jan 5, 2020 in Web Technology by ashely (50.2k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...