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

Pagination on subdocuments #129

Open
Mdhaker opened this issue Jan 3, 2018 · 4 comments
Open

Pagination on subdocuments #129

Mdhaker opened this issue Jan 3, 2018 · 4 comments

Comments

@Mdhaker
Copy link

Mdhaker commented Jan 3, 2018

This is my schema
const schema = new mongoose.Schema({ // User profile data saved here profile : { }, trainings:[training], // User training courses data saved here sessions:[session], slug: { type: String }, path: { type: String }, slugs: { type: [String] }, createdAt: { type: Date, default: Date.now }, updatedAt: { type: Date }, status: { type: String, enum: userStatus, default:"inactive" }, }
Is there away to paginate the array of subdocuments lik trainings and sessions ?

@ghost
Copy link

ghost commented Jan 18, 2018

@Mdhaker - Have you possibly got a solution to this? Looking to do something similar

@carvalhoviniciusluiz
Copy link

you could use aggregation framework - $unwind the array of subdocuments and then use $sort and $limit.

@IskanderMustafin
Copy link

IskanderMustafin commented Dec 13, 2018

If I understand correctly, in case of using aggregation framework we lose all Mongoose features, like methods, virtuals, post/pre hooks etc, because returned result is raw object, not wrapped by Mongoose.

Is it right?

If yes, then using aggregation with Mongoose don't have any sense.

@snowdream
Copy link

I want to know how to paginate on subdocuments .

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

4 participants