How to build this db model
Working on a NoSQL implementation of this discord bot me and my friend are setting up. What it'll do is iterate through all messages and get the amount of emojis each user has across all their messages.
I was wondering what a good model for this would be? Should we build a model for each User, and then iterate through all their emojis? I have this so far:
This way, we can just do something like:
4 Replies
Could you the counts of each emoji in your db? It seems like the list of emojis could get voluminous quickly.
You have to do a db update for each emojiing event anyway.
It'd definitely speed up the calculation.
(Also, your sort should return
userBCount - userACount
since it's expecting a positive, 0
, or negative value.)Hey dys! Do you mean I should get the count of a specific emoji in the backend instead of the frontend? e.g have an endpoint like
/get/emoji/:emojiId
and that way we're limiting the amount of work the bot has to do?I actually misread your code. Because you used an array, I assumed you were tracking all the emojis in a list.
Your structure is actually what I was suggesting. 😸
How I'd change what you have is to use a map, so you have
user.emojiCount = { chart: 10, … }
(so you can call user.emojiCount['chart']
) rather than user.emojis = [{ emoji: 'chart', count: 10 }, …]
& have to find the count.No worries 😂 and that's smart! I'll try that, thank you!! 🙂