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

mongoosePaginate.options block toJSON and toObject #160

Open
richardpickett opened this issue Feb 22, 2022 · 3 comments
Open

mongoosePaginate.options block toJSON and toObject #160

richardpickett opened this issue Feb 22, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@richardpickett
Copy link

Describe the bug
Whenever you set paginate options on the schema, any toJSON and toObject calls you have won't be called.

To Reproduce
Steps to reproduce the behavior:

  1. On an existing collection that paginate() currently works on, add toJSON:
// THIS:
  schema.options.toJSON = {
   transform: (doc, ret) => {console.log("your data", ret); return ret;}
  };
// OR THIS:
  schema.method("toJSON", () => {console.log("your data", ret); return ret;});
  1. Run your paginate call like normal, you should see the console log "your data" along with the results.

  2. Then add paginate options prior to adding pagination, it doesn't seem to matter what the options are, you can even set them to a blank object, {}:

mongoosePaginate.paginate.options = {
  lean: true,
  customLabels: {
    totalDocs: "total",
    totalPages: "pageCount",
  },
};

// .....

schema.plugin(mongoosePaginate);
  1. Now when your pagination runs you won't get the console log as before.

Please note, the console log is just for testing, the point is toJSON/toObject never get called if you add any pagination options.

Expected behavior
Setting pagination options shouldn't interfere with other calls like toJSON.

Screenshots
NA

Desktop (please complete the following information):

  • OS: linux
  • Browser NA
  • Version 1.6.2

Smartphone (please complete the following information):
NA

Additional context
NA

@aravindnc aravindnc added the bug Something isn't working label Jun 8, 2022
@aravindnc
Copy link
Owner

I have spent sometime with this, and no idea what's causing this issue.

@baladin
Copy link

baladin commented Jul 1, 2022

I am facing this issue also. I am using this plugin with @meanie/mongoose-to-json, but all private fields are leaked.

@mtShaikh
Copy link

any update on this? I'm facing the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants