Hi first of all sorry for asking such a silly question, for a school project i am making a lottery system in MongoDB So i am adding users in my Collection with a lottery id {which is same for every user } , user_id { which is a unique value } , Now i want to fetch a single user Using Lottery id And declare him as a winner How can i do that or is there nay better system i should follow ? i am using python for this ,i Hope that the message i want to convey is clear Thanks For reading , have a good day
            Asked
            
        
        
            Active
            
        
            Viewed 33 times
        
    1
            
            
        - 
                    Please provide enough code so others can better understand or reproduce the problem. – Community Aug 30 '22 at 07:33
1 Answers
0
            Try this:
db.mycoll.aggregate([
        { $match: { lottery_id: 10 } },
        { $sample: { size: 1 } }
    ])
You might want to see this solution for more information.
I hope it helps. :D
 
    
    
        Circuit Planet
        
- 161
- 8
