aravindnc / mongoose-aggregate-paginate-v2

A cursor based custom aggregate pagination library for Mongoose with customizable labels.
MIT License
131 stars 23 forks source link

Not paginated the result for $group, $facet, or even $unwind #4

Closed mandaputtra closed 4 years ago

mandaputtra commented 5 years ago

Just tried this aggregation with, $unwind $group or $facet it always serializes the docs to be one.

    Chat.aggregate([
      { $match: { roomId: unique } },
      { $unwind: '$message' },
      { $sort: { 'message.time': -1 } },
      { $group: { _id: "$_id", message: "$message.text" } } 
    ])
aravindnc commented 5 years ago

@mandaputtra I will review it and get back.

mandaputtra commented 5 years ago

Just for info, I get around this issue with $facet

// assume that page and limit are query params contains number 
{
  $facet: {
     metadata: [{ $count: 'total' }, { $addFields: { page: page } }],
     data: [
       { $skip: page === 1 ? 0 : (page - 1) * limit },
           { $limit: limit }
      ]}
}
aravindnc commented 5 years ago

@mandaputtra Glad to hear that.

mandaputtra commented 5 years ago

I'll do some test in my free time, and maybe if this was bug ill try to pull request. But that could be a major change. Lest see..

aravindnc commented 5 years ago

@mandaputtra Appreciate it. You're awesome!

gezimapi commented 4 years ago

hi ,

i am having the same problem . it always serializes all the docs in the collection one by one not the result in aggregate.

mandaputtra commented 4 years ago

@gezimapi I custom paginate it, with $facet. I wrote an articele here.

It will be a major change if the feature merged,

aravindnc commented 4 years ago

Thanks @mandaputtra