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

Ignores Schema if used as Mongoose Plugin #47

Open
uncledent opened this issue Sep 10, 2018 · 3 comments
Open

Ignores Schema if used as Mongoose Plugin #47

uncledent opened this issue Sep 10, 2018 · 3 comments

Comments

@uncledent
Copy link

It ignores virtuals and hidden fields with { select: false }.

Does anyone know a workaround for that?

@uncledent
Copy link
Author

If you need just the mongoose plugin which will use your mongoose model, you can try this lib: https://github.com/uncledent/mongoose-cursor-pagination-plugin

It is fully based on this library, but there is the mongoose plugin only, other stuff is removed. It uses mongoose model instead of raw mongo driver.

@sangdth
Copy link

sangdth commented Dec 29, 2019

I have tried your plugin but I face another problem. When I use with nestjs, I have to declare the model while injecting:

    @InjectModel('Item') private ItemModel: PaginateModel<Item>

In your plugin there is no PaginateModel so the nest can not work, do you have another solution for this? I really need to make the virtual works.

@uncledent
Copy link
Author

uncledent commented Dec 29, 2019

@sangdth You can just create an interface by your own and use it:

export interface PaginatedModel<T extends Document> extends Model<T> {
  paginate(paginantionOptions: any): PaginationResult<T>;
}

tomyam1 added a commit to tepez/mongo-cursor-pagination that referenced this issue Jun 22, 2021
Before we used the collection instead of the model
As a result all the goodness of mongoose is lost

For instance
* queries are not casted to the schema, e.g. strings are not converted
to ObjectIDs
* Simple objects are returned instead of mongoose Documents

Replace object-path get with dot-prop get
Because object-path only return own properties
https://github.com/mariocasciaro/object-path/blob/v0.11.0/index.js#L233
and mongoose _id properties are inherited from the Document
use object-path will return undefined instead

This should probably fix:
mixmaxhq#47

BREAKING CHANGE: This changes the behavior of the mongoose plugin thoroughly

squash
tomyam1 added a commit to tepez/mongo-cursor-pagination that referenced this issue Jun 22, 2021
Before we used the collection instead of the model
As a result all the goodness of mongoose is lost

For instance
* queries are not casted to the schema, e.g. strings are not converted
to ObjectIDs
* Simple objects are returned instead of mongoose Documents

Replace object-path get with dot-prop get
Because object-path only return own properties
https://github.com/mariocasciaro/object-path/blob/v0.11.0/index.js#L233
and mongoose _id properties are inherited from the Document
use object-path will return undefined instead

This should probably fix:
mixmaxhq#47

BREAKING CHANGE: This changes the behavior of the mongoose plugin thoroughly

squash
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