mongoosePaginate.options block toJSON and toObject
richardpickett opened this issue · comments
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:
- 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;});
-
Run your paginate call like normal, you should see the console log "your data" along with the results.
-
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);
- 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
I have spent sometime with this, and no idea what's causing this issue.
I am facing this issue also. I am using this plugin with @meanie/mongoose-to-json, but all private fields are leaked.
any update on this? I'm facing the same issue