I am using lean, (This makes queries faster and less memory intensive, but the result documents are plain old JavaScript objects (POJOs),)
By default this will block all getters execution and provides POJO (plain old java object) so as a solution we can use mongoose-lean-getters as per the standard doc
without getter :
"rate_photo": "rate/1574154457920-myw3schoolsimage.jpg",
With getter :
"rate_photo": "http://192.168.15.93:6600/assets/uploads/rate/1574154457920-myw3schoolsimage.jpg",
With lean:
"rate_photo": "rate/1574154457920-myw3schoolsimage.jpg",
With lean and findOne:
"rate_photo": "http://192.168.15.93:6600/assets/uploads/rate/1574154457920-myw3schoolsimage.jpg",
With lean and find: // <------------ ISSUE
expected result :
"rate_photo": "http://192.168.15.93:6600/assets/uploads/rate/1574154457920-myw3schoolsimage.jpg",
BUT GOT THIS :
"rate_photo": "http://192.168.15.93:6600/assets/uploads/http://192.168.15.93:6600/assets/uploads/rate/1574154457920-myw3schoolsimage.jpg",
I have also found the reason behind the issue, in the npm package, they are calling getter twice via middleware 1st from pre and second from post and this is only for find method alone :
I am using
lean
, (This makes queries faster and less memory intensive, but the result documents are plain old JavaScript objects (POJOs),)By default this will block all getters execution and provides POJO (plain old java object) so as a solution we can use
mongoose-lean-getters
as per the standard docSchema :
Issue :
Output:
I have also found the reason behind the issue, in the npm package, they are calling getter twice via middleware 1st from
pre
and second frompost
and this is only forfind
method alone :So If I comment out one of them ti works great, but the code is there for some reason, so Is there any better way to go ahead ?