CRUD Operations: Find
🚀 Goal: Find, Sort & Paginate Like a Pro
Your company’s journey into the short-term rental market has just begun, and the first challenge is clear: you need to help your users discover the perfect place to stay. As the backend engineer, it’s your job to make searching listings fast, accurate, and delightful.
In this exercise, you’ll master the basics of MongoDB by finding documents, sorting results, and adding smooth pagination to your queries. This is the foundation of every great rental platform—making sure guests can easily browse and explore what your company has to offer.
đź§© Exercise: Find Documents
-
Open the File
Head toserver/src/lab/
and opencrud-1.lab.js
. -
Locate the Function
Find thecrudFind
function in the file. -
Shape the Query
- Find all documents matching the provided
query
parameter. - Sort results by
_id
in ascending order. - Add pagination with:
skip
: number of documents to skiplimit
: maximum documents to return
- Find all documents matching the provided
🚦 Test Your API
- Go to
server/src/lab/rest-lab
. - Open
crud-1-lab.http
. - Click Send Request to execute the API call.
- Check that the response returns the paginated results.
- Run the Test Suite:
cd server/ npm test
🖥️ Frontend Validation
Once your backend logic is in place, refresh the homepage and watch as your listings appear—ready for your future guests to explore. Scroll through the results and see pagination in action: smooth, fast, and just how users love it.
With this first step, you’re not just writing code—you’re building the search experience that will help your company stand out in the rental market.
Ready to help your users find their next stay? Let’s get started!