Fetching data from a database, filtering it by only guilds handled by the shard

I have a database containing data about multiple guilds, and i have to fetch some generic data (not necessarily related to a guild in particular), but I want to restrict the results to the entries that have their guild handled by the current shard. Database is MongoDB, and I use Mongoose. Now, I have found a few possible solutions, like: - Filtering the data after having received it from the DB. This potentially results in a lot of memory waste for entries that are better handler by other shards - Use $in and pass client.guilds.cache.map(g=>g.id), which seems a bit weird considering a shard can be handling a lot of guilds at once - Use $where, and use the bitwise shift formula, hoping mongo supports BigInt Is there an efficient way to make this filter, or something I haven't thought of?
8 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
MoonlightCapital
MoonlightCapitalOP2y ago
yes, i know about it
d.js docs
d.js docs2y ago
method (static) ShardClientUtil.shardIdForGuildId() Get the shard id for a given guild id.
MoonlightCapital
MoonlightCapitalOP2y ago
but i'm asking, where do i best use it?
Syjalo
Syjalo2y ago
Anything else not related to discord.js
Syjalo
Syjalo2y ago
MoonlightCapital
MoonlightCapitalOP2y ago
so i pretty much have to get all the data, and filter it with this later in the bot?
Want results from more Discord servers?
Add your server