DEV Community

Discussion on: The right way to make advanced and efficient MongoDB pagination

Collapse
 
dhensen profile image
Dino Hensen

Oh I get the $unwind: '$total': it is because the field count that gets created has an array as value with a single integer element inside of it. Unwind creates a document foreach element in that array, but because there is only one it effectively pulls the single integer out of the array and uses that. Without this unwind the $divide errors about one value being an array.