Sorry for the vague title had trouble trying to word it.

Essentially I'm making a Discord bot and I'm making a ranking system for it. I have Users and Guilds collections and I'm wondering how I'd establish ranks for each user per guild. A user can be in multiple guilds and obviously guilds can have multiple users.

The schema(s) of Guilds and Users as of current doesn't matter much but the data I'm trying to store for each user in each guild is as follows:

    user_id: int32
    guild_id: int32
    background: string
    level: int32
    points: int32

Currently the way I have been storing the data is in it's own collection called GuildUsers but this feels wrong as they are small documents and there's repeated data in this case kind of like a sql many to many relationship.

I'd like to embed these documents into either Users or Guilds although am having trouble deciding which one as I still need to have aggregations for the highest level user(s) globally (across all guilds) and highest user(s) for a particular guild.

Currently all I need to do to get the top 10 in a server is:

db.guild_users.find({_id:guild_id}, options={sort: [('level', -1), ('points', -1)], limit: 10})

And for top 10 overall just omit the filter. But how would I go about this if it was embedded and what would be the best collection to embed the data in?

  • 1. What is the maximum number of users associated with a guild? 2. What is the average document size of a single user document? do you have any other access pattern to your data? – Mani Jul 15 '19 at 6:07
  • 1. There is no maximum users per guild. 2. Average user document size is small maybe 400-500B. And I don't think I understand what you mean by access pattern? I can organize how I'd like this is in planning stages not production. – Jab Jul 15 '19 at 8:56
  • I mean what is the possibility of the maximum number of users per guild. Access pattern means, how your different select queries looks like. – Mani Jul 15 '19 at 20:18
  • I don’t see member count rarely reaching or going over 200k, average I see is 1-2k per guild. As for access pattern, currently with Members collection acting as a relationship between Users and Guilds I have not been using aggregations as it’s been easy enough for me to just findone user with their id and same concept with guilds like my example in the question. I just do the math in python. I see writes being more important than reads as writes are happening multiple times per second although not to the same Document. Apologies for the lack of examples it’s late here will check tomorrow – Jab Jul 15 '19 at 23:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.