I'm using mongoose-paginate-v2 to paginate my documents, and I use lean=true to make them a plain Object (I want to filter them using accesscontrol.
When I get the leaned Objects , all ObjectIds are in Object formate like below:
{"_id":{"_bsontype":"ObjectID","id":{"type":"Buffer","data":[95,94,16,4,98,8,156,8,236,35,179,155]}}
I get that its the way that MongoDB handles it but I want to send String ObjectId to the client (so that it can access resources with that Id). I know that by using vituals and id instead of _id I can get the string representation of that object's _id, but the problem is I want All ids to be string, not just the id of the object.
If I try to write a middleware that changes all id objects to string representation, I'll need a way to deep find all ids in my result , which I don't know how to do.
How an I have all ids in string format, yet still have leaned object?