Hi everyone!
I wanted to ask community what is the preferable architecture / way of storing data which is frequently updated?
For example I have an user collection and every user has his in-game quests.
Quests have their progression which will be very often modified / updated.
Exemplary user would look like this:
{
"_id": { "$oid": "xxxxxxxxxxxxxxxxxxxxxxxx" },
"user_id": 1,
"quests": [
{
"startDate": { "$date": "2021-07-18T13:30:36.617Z" },
"endDate": { "$date": "2021-07-18T13:30:46.617Z" },
"reward": {
"_id": { "$oid": "60f4102d59380d229455b530" },
"xp": 300,
"currency": 200
},
"conditions": [
{
"type": "play",
"details": {
"_id": { "$oid": "60f42cfc5a79ef478c5938ab" },
"count": 10,
"winAtleast": 5,
"loseMax": 2
},
"progress": {
"gamesInRow": ["win", "lose", "lose"]
}
}
]
}
]
}
At first I thought nested arrays / embedded docs are the way to go, because there is one to many relation, where every user has multiple quests but they are unique for them.
But when I started programming an API for it to update this structure I got a big problem with deep merge (javascript driver). I want to have a nice way to update progress fields and these updates will be very frequent. I read about arrayFilters and dot notations to make this possible but the code with this design is very messy.
The main problem for me now is to transform object which looks like user object but with updated fields on every “nesting level” to update / updateMany function with all those arrayFilters etc.
I know how to change single field but I would like to have one resuable function with whole object as parameter to update only these fields which are changed not replace whole user everytime.
Maybe I can achieve this by breaking this structure into multiple collections? Still I would love to know preferable and efficient way to do frequent operations on nested objects / arrays.
I hope everyone of You will have a great day!