Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add paginate on subdocuments list #174

Closed
lau1944 opened this issue Jun 24, 2022 · 7 comments
Closed

Add paginate on subdocuments list #174

lau1944 opened this issue Jun 24, 2022 · 7 comments

Comments

@lau1944
Copy link
Contributor

lau1944 commented Jun 24, 2022

I want to add pagination features to sub-docs list

for instance

We have a user model which contains followers

const userModel = new Schema({
  id: { type: String },
  followers: [{ type: ObjectId, ref: 'user'  }]
});

Now, when we need to fetch the followers of a user

user.findOneById(id).populate('followers');

But here I want to paginate the followers list, but I cannot use the api from this library to achieve this.
Instead I need to

user.findOneById(id).populate({ path: 'followers', limit: xx, skip: (page - 1) * limit, ...  );

That adds some extra code...

Is there any way to do that in this library ?
If not, I am here to submit a feature request. If you need any help, I am eager to contribute.

@aravindnc
Copy link
Owner

@lau1944
Copy link
Contributor Author

lau1944 commented Jun 24, 2022

@lau1944 You can try this.

https://www.npmjs.com/package/mongoose-aggregate-paginate-v2

I took a look but I don't think aggregation can be used in my use case.

Maybe we can add a way to paginate sub-docs ?

@aravindnc
Copy link
Owner

@lau1944 Yes its good to add as an option. You are welcome to contribute if you are willing.

@lau1944
Copy link
Contributor Author

lau1944 commented Jun 25, 2022

How about I add a second method, let say paginateSubDocs, if user want to paginate only sub-documents, they can add this function to their schema. And this function only support findOne query.

@aravindnc
Copy link
Owner

@lau1944 Excellent. Let's start with this.

@lau1944
Copy link
Contributor Author

lau1944 commented Jun 26, 2022

Thanks! I am working on it, will pr in a few days ><

lau1944 added a commit to lau1944/mongoose-paginate-v2 that referenced this issue Jun 26, 2022
lau1944 added a commit to lau1944/mongoose-paginate-v2 that referenced this issue Jun 26, 2022
lau1944 added a commit to lau1944/mongoose-paginate-v2 that referenced this issue Jun 26, 2022
@lau1944
Copy link
Contributor Author

lau1944 commented Jun 27, 2022

@aravindnc would you like to take a look #175

aravindnc added a commit that referenced this issue Jun 30, 2022
feat: add sub-document pagination (feats: #174)
@lau1944 lau1944 closed this as completed Jul 1, 2022
aravindnc added a commit that referenced this issue Jul 4, 2022
feat: remove defaultOptions in subdoc pagination process #174
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants