I am trying to develop a Tambola(Bingo) game web application using Nodejs and MongoDB. Database has been named as ticketdb which has the collection named as tickets containing documents of bingo ticket pattern tkt and information about bingo ticket owner as shown below. Bingo ticket is a table layout having 9 columns and 3 rows which contains 15 non-repeated random numbers between 1-99 placed randomly on the ticket layout. I have shown only two documents but there are up to 500 documents. (Note: each and every ticket pattern are unique and do not match with one another).
{"_id":1,
"name":"Johnson",
"phone_no":123456789,
"tkt":[
["",12,25,"","",52,60,"",86],
[1,17,29,"",43,"","","",89],
[3,"","",34,45,"",62,70,""]
]
},
{"_id":2,
"name":"Bob",
"phone_no":123456789,
"tkt":[
["","","","",41,53,60,76,82],
[1,"","","","",52,66,77,83],
[2,"","",32,"",59,68,"",89]
]
}
]
When the game starts, in the server side every 5 secs a random number is generated between 1-99 which is non-repeated and have to be matched from tkt every time it generates the number and when numbers of some specific pattern is matched from the ticket layout then the winner of that pattern will be drawn.
- Pattern example:
- Top line - winner will be drawn if all the numbers in top row is matched.
- Middle line - winner will be drawn if all the numbers in middle row is matched.
- Bottom line - winner will be drawn if all the numbers in bottom row is matched.
- Full house - winner will be drawn if all the numbers of the ticket is matched.
Now, my question is how write code for matching the randomly generated numbers with the numbers in tkt to draw the winner? I searched about MongoDB query method and Aggregation pipeline method but it didn't helped me and felt that it will be a complex process to write the code as I'm just a beginner and new to coding and this is my first ever project. Any help will be appreciated and really sorry if there is any mistake in my writing. Thanks in advance.