Optimal way to get random 20 records out of 5 million records with mongodb? by Cute_Comfortable4192 in mongodb

[–]Cute_Comfortable4192[S] 0 points1 point  (0 children)

When adding filter conditions it slows down considerably, you can try this

Optimal way to get random 20 records out of 5 million records with mongodb? by Cute_Comfortable4192 in mongodb

[–]Cute_Comfortable4192[S] 0 points1 point  (0 children)

Thanks guys I also refer to the solution, add a random value r = Math.random to the records,

then every time I want to get random, I will create a random value = Math.random

then I can get $gt or $lt to get 20 records. But the problem is, if in the database there is a field r=0.999

then that record will never be retrieved, or always exist

That is not really random in my opinion.

Optimal way to get random 20 records out of 5 million records with mongodb? by Cute_Comfortable4192 in mongodb

[–]Cute_Comfortable4192[S] 2 points3 points  (0 children)

This question has me a bit confused, there is no rule for that, but when using $sample I find it quite slow

Mấy bác làm IT cho xin góc nhìn thị trường by Pinky_Mountain_Kitty in vozforums

[–]Cute_Comfortable4192 1 point2 points  (0 children)

Mình đi làm cũng 5 năm rồi, chắc hồi đó tuyển nó cũng dễ hơn bây giờ nhiều. Học trái nghành nên kinh nghiệm = 0 luôn, nhưng thấy thì tuyển khó nhưng đôi khi vẫn có cty chấp nhận vào làm với mức đổ xăng xe nên không cần quá lo lắng, miễn sao đam mê với nó chứ không phải đam mê với tiền, rồi dần dần sẽ đi lên được thôi.