#79 Pagination | Using MongoDB with Express| A Complete NODE JS Course

  Рет қаралды 9,058

procademy

procademy

Күн бұрын

Пікірлер: 12
@kurikodudewe2734
@kurikodudewe2734 Жыл бұрын
you are the best teacher sir you explain it clearly with good example
@anshulrajput6316
@anshulrajput6316 6 ай бұрын
Using pagination will break the filter method as it will modify the query at the end. Thus, in Postman, we will obtain all movie lists when filtering as defined by const limit = (entered limit is empty when filtering) || 10 .
@bmsos
@bmsos 11 ай бұрын
Hello, from minute 06:42 you can see that page 1's first doc is the movie Divergent, and then when you switch to page 2 the same movie shows up. The same thing is happening to me. Because of this some movies are not shown in any of the pages. Any solution? Thank you in advance and congratulations for this course.
@bmsos
@bmsos 11 ай бұрын
Ok I figured it out. Found this on the internet: "We recommend always using limit() with sort(). If you don't specify sort(), the MongoDB server doesn't guarantee you'll get the results back in any particular order." Since we were setting a default sorting by -createdAt, and that property had the same value in all docs (since they were all imported at the same time from the json file), the sorting wasn't giving any effective order to the list. Changed the default sort to '-name' and it worked perfectly.
@muneerhussain490
@muneerhussain490 7 ай бұрын
@@bmsos It was happening with me too and thank you for the solution
@DuyHoang-ul7lg
@DuyHoang-ul7lg 7 ай бұрын
thank you for the solution
@anuragh3
@anuragh3 5 ай бұрын
the complete code const excludeFields = ['sort', 'page', 'limit', 'fields'] const queryObj = { ...req.query } excludeFields.forEach((el) => delete queryObj[el]) //Advance Filtering (greater than/ less than/ greater than equal to/ less than equal to) let queryStr = JSON.stringify(queryObj) const regex = /\b(gte|gt|lte|lt)\b/g queryStr = queryStr.replace(regex, (match) => `$${match}`) const queryObj1 = JSON.parse(queryStr) //Sorting with one or more conditions let query = Movie.find(queryObj1) req.query.sort ? query.sort(req.query.sort.split(',').join(' ')) : query.sort('-name') //Limiting Fields req.query.fields ? query.select(req.query.fields.split(',').join(' ')) : query.select('-__v') //Pagination const page = +req.query.page || 1 const limit = +req.query.limit || 5 const skip = (page - 1) * limit query = query.skip(skip).limit(limit) if (req.query.page) { const moviesCount = await Movie.countDocuments() if (skip >= moviesCount) throw new Error(' There are no records to display!!') } const movies = await query
@AjayCoding
@AjayCoding Жыл бұрын
@rishiraj2548
@rishiraj2548 Жыл бұрын
Thanks
@soundarTech
@soundarTech Жыл бұрын
jonas copy paste !!!!!!!!!!!!!!! 🥲🥲🥲🥲
@sachinsridharan99
@sachinsridharan99 Ай бұрын
delete querryObj.page; delete querryObj.limit; delete querryObj.sort delete querryObj.fields console.log(querryObj); let query = Movie.find(querryObj); add this if pagination is not working
Amazing remote control#devil  #lilith #funny #shorts
00:30
Devil Lilith
Рет қаралды 16 МЛН
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 51 МЛН
Players push long pins through a cardboard box attempting to pop the balloon!
00:31
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 67 МЛН
Mongoose Tutorial 03: Validating Data in Mongoose
24:20
OneCodeCamp
Рет қаралды 373
Create A Paginated API With Node.js - Complete Tutorial
23:21
Web Dev Simplified
Рет қаралды 197 М.
CRUD REST API using Node | Express | MongoDB
52:35
Telusko
Рет қаралды 383 М.
Complete MongoDB Tutorial #23 - Pagination
7:15
Net Ninja
Рет қаралды 61 М.
My New Favorite Pagination Method
5:45
Josh tried coding
Рет қаралды 88 М.
Amazing remote control#devil  #lilith #funny #shorts
00:30
Devil Lilith
Рет қаралды 16 МЛН