Pagination with Mongoose DB
I have a command where a user can add like reminders to the database. I have a command that shows the list of reminders but now i want the user to be able to go through a list of his reminders with two buttons. On every page there should only be 5 reminders because i have a feature that allows the user to mark the reminders with successful or not successful via buttons (see picture). How can I do that?
14 Replies
• What's your exact discord.js
npm list discord.js
and node node -v
version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.Get all the reminders and paginate them or get chanks of pages from the db. Anyway not related to discord.js.
Yeah but how do I do that
Paginating embeds involves iteration and handling data in an organized manner
I also wanted one for my auto responder commands
Searched the web intensively for examples. even asked chatGPT and got a broken response.
But got the inspiration and created a successful system in the end
@devkavi I tried it the same way as you and I'm totally aware of #rules 5 but I've been sitting on this for a couple of days now and I just can't make it work. I would really appreciate it if you sent me your code or the concept.
But how do I code it so that it changes the page?
No, i mean how do I display the new information and when the user selects to go back a page to show the first 1-5 things
and how do I only get the 6-10 elements for that page?
bruh
That’s not what I meant
how do I get what page the user is currently on?
lets say i put it in the footer of the embed, how could i read that?
yea but how do i do that
i know that is prob basic js, but if my footer was 'Page 1/3', how would i only get the 1 and 3 out of that?
so i would do something like ?
i got this:
why didn’t it work like that? or what do I have to change?
Mine is a TypeScript based Class.
I'll explain what I did. It's up to you to create something that matches your use case.
My class takes a string array as an input, which has all the string data, like for example all the names I want to display.
Like 30 to 50 names.
Inside my class I've defined a default
chunkSize
which says the iteration how much should one page show. 5 names at default.
Then I have createChunkArray()
function, which has it's own chunkArray
defined inside as an empty array.
And now it checks if the given data size is less than the defined chunk size, if true, does nothing and pushes all the data.
if false. I run a for loop like this.
Which is the bulk of the code actually where it breaks down all the data into different chunks for different embeds to display.
Then I have a createEmbed()
function which creates one embed for one chunk
looks something like this.
Then I have the main function called sendEmbeds()
which takes a channel argument, actually puts 1 + 1 together and finalizes the process and sends to discord, with buttons and collectors which handles interactions.
I hope this will be enough to give you an headstart at least. Good luck.
This is just for reference
And to get a logical idea on how to execute your idea
<:E_think:793918036787986453> am regretting my past decisions now That’s really not true
at this point I was already looking through the docs btw
so could you please help me with this?
I meant my problem from yesterday
.
That’s not true
where in discordjs docs should I find the answer to my problem??
I fixed myself but thanks