Here is my current mongoDB database idea:
alliance info collection
{
"name": "guild1",
"id": abcd,
"totalExp": 10101001010101,
"tag": "GUILD_ONE"
},
{
"name": "guild2",
"id": abce,
"totalExp": 10101001010101,
"tag": "GUILD_TWO"
}
member collection
{"member_id": 1111,
"current_alliance": "guild1",
"alliances": {"guild1": {"11-05-2021": 100000,
"12-05-2021": 100000,
"13-05-2021": 100000,
"14-05-2021": 100000,
"15-05-2021": 100000,}
},
{"guild2": {"06-05-2021": 100000,
"07-05-2021": 100000,
"08-05-2021": 100000,
"09-05-2021": 100000,
"10-05-2021": 100000}
}
},
{"member_id": 2222,
"current_alliance": "guild1",
"alliances": {"guild1": {"11-05-2021": 100000,
"12-05-2021": 100000,
"13-05-2021": 100000,
"14-05-2021": 100000,
"15-05-2021": 100000,}
}
}
Info
-I am trying to store an unlimited number of days experience for EACH member.
-I thought they could each get their own document otherwise the alliance info documents would become massive over time.
-Members can join and leave different alliances, but I am trying to keep all their experience history for all their alliances they have been in.
-Language is python.
-Each alliance can have a total of 100 current members.
-I want to store member’s experience for an alliance even if they leave it.
-For each document in the alliance info collection their will be up to 100 documents in the member collection.
Reading
Queries will be per alliance, so if I was querying “guild1”, I would need to select 100 documents from the member collection.
If i had an index for “current_alliance” I thought I could use this query to select all members from one:
cursor = db["member"].find({'current_alliance': "guild1"})
Updating
Each day I will add the member’s daily experience for the current alliance they are in, so an example for updating “guild1”:
result = await db["member"].bulk_write([ UpdateOne( {"member_id":1111},{'$set': {'alliances.guild1.15-05-2021': '100000'}}),
UpdateOne({"member_id":2222},{'$set': {'alliances.guild1.15-05-2021': '100000'}})
#...for uo to 100 members...
ordered=False)
Thoughts
-Both the queries above seem to work however i dont know how optimal bulk_write() or find() are?
-Is doing a bulk_write() for 100 documents in one collection OK?
-And also when I need to retrieve data I have to select all 100 member’s documents from the member collection before i can do anything (for one alliance).
-Does this model look OK?
Thanks very much!