Hi! I’m new to NoSQL Db’s and I’m having a seriously hard time figuring some stuff out. I’ve been watching some of the vidos en the MongoDB youtube channel and now I have a few guideliness to go with, however, I’m having a seriously hard time thinking what is the “correct” or “most efficient” way of building my documents for a specific project.
I have several little “books” (really tiny) with 100 tickets each and the books can have different prices per ticket. They all have a specic series and a correlative. for example, AA 10290 to AA 10390, exactly 100.
I need to prepare the “service” and give away a plastic bag with several of those books for them to go and sell each ticket. It should like something like this:
01 Huge Jackman
Book | N tickets
AA 1000 - 1100 | 100
AA 1200 - 1300 | 100
AA 1400 - 1500 | 100
When they come back, they could have sold the entire first book with 100 tickets. and come back with half of another.
AA 1000 - 1100 | sold out
AA 1200 - 1250 | 50
AA 1400 - 1500 | 100
Next “service” I prepare I will use the half sold book:
AA 1250 - 1300 | 50
AA 1400 - 1500 | 100
AA 1600 - 1700 | 100
And the process repeats.
This is where the problem arrises. How do I keep track of all those tickets? should I create a document with 2 arrays for each book like this:
{
_id: 10293812
for_sale: [ 1000, 1001, 1002, ..., 1100 ]
sold: []
}
assign the object id to the service document (or should i embed the entire book document in the service document?) and when the employee returns update the arrays values from for_sale to sold?
According to some videos i watched, i should embed everything that can be embedded into just one document. So it should look like this:
{
_id: 120938,
employee: {
_id: 102398734
name: Huge Jackman
},
date: 2023/01/01,
books:{
book1: {
_id: 7987234,
serie: "AA",
for_sale: [1000, 1001, ..., 1100],
sold: []
}
},
book2: {
_id: 76598,
seria: "AA",
for_sale: [1200, 1201, ..., 1300],
sold: []
}
}
Each ticket of each book is unique with serie+correlative, I can’t have a repeated book with serie “AA” and correlative 1000 in any other service.
Thank you so very much for your guidance!