I'm trying to learn more express and mongodb, so I'm working on a feature that allows a user to search for quotes with certain words in them. So far I'm using mongoose-search-plugin npm module to handle the searching and displaying of the quotes; but I don't want to just display all the quotes on one page when a user searches. So far I've been able to limit the amount of quotes a search brings to just 10 quotes using mongoose-search-plugin npm module, but I'm stuck because I don't know how to implement a <next> button feature so that the user can click on it to see more quotes that matched his search. Can anyone please give me any pointers? Any help kind of help is gratefully wolfed down.
Emmanuel
Vasan Subramanian
Previous generation techie
I think what you are looking for are the
offset()andskip()functions available on the result offind()either directly using the MongoDB driver or via Mongoose. I believe the plugin you are using should also have support for these functions.You should also be aware of caveats when using these when the total number of pages could be large. In fact I have devoted a full section to discuss pagination in my book Pro MERN Stack, the code for which you can find in this github repo. You could directly use that code if you are using React and Bootstrap, but could use the concepts otherwise.