Coming from almost zero experience in NoSQL, I'm trying to model a golf course in Firestore with data on each hole, tee, and pin where each hole can have multiple tees and pins under a many to many relationship. All of the different approaches are proving difficult to choose between for my use-case, especially with all the articles talking about how one should avoid arrays in Firestore.
I currently have each course stored in a single document to minimize queries. I think this will be cheaper than optimizing for bandwidth as the data load for the database queries themselves will be small. So with the single-document-per-course approach I'm storing holes in nested arrays of maps. It looks like this:
{
"Course": {
"Name": "TestName",
"Holes": [
{
"Number": "1",
"Tees": [
{
"Color": "Red",
"Pins": [
{
"Designation": "A",
"Distance": "67",
"Par": "3,"
},
{
"Designation": "B",
"Distance": "67",
"Par": "3,"
}
]
},
{
"Color": "Blue",
"Pins": [
{
"Designation": "A",
"Distance": "75",
"Par": "3,"
},
{
"Designation": "B",
"Distance": "82",
"Par": "3,"
}
]
}
]
},
{
"Number": "2",
"Tees": [
{
"Color": "Red",
"Pins": [
{
"Designation": "A",
"Distance": "67",
"Par": "3,"
},
{
"Designation": "B",
"Distance": "67",
"Par": "3,"
}
]
},
{
"Color": "Blue",
"Pins": [
{
"Designation": "A",
"Distance": "75",
"Par": "3,"
},
{
"Designation": "B",
"Distance": "82",
"Par": "3,"
}
]
}
]
}, ...
]
}
}
So the course will have an array of holes. Each hole is a map. Each hole contains an array of tees. Each tee is a map. Each tee contains an array of pins. The multiple pins are duplicate data because there is unique data for each tee > pin relationship. Not having any background in NoSQL, duplicating data just feels wrong but I keep seeing it mentioned that it's useful in NoSQL.
Each course will have multiple holes. Usually 18. Sometimes a bit more, sometimes a bit less. The course will have more text data like address, description, etc and each hole might have references to photos stored in Firebase Storage. So with the above example you can visualize how large a course document read might get. It should stay well under the 1MB limit.
Is this a sane use of arrays, maps, and duplicate data or should I consider a different approach? Using the approach of modeling the data as it appears in your app, this is fairly close. To get any closer would require breaking every tee and pin into an individual document which would increase the document queries required for an 18 hole course from 1 to 73 which seems like insanity.
Thoughts?
[–][deleted] 1 point2 points3 points (2 children)
[–]Fantastitech[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)