feathersjs-ecosystem / feathers-mongoose

Easily create a Mongoose Service for Feathersjs.
MIT License
189 stars 96 forks source link

lean is not correct in documentation and actual behavior #427

Open dor-benatia opened 2 years ago

dor-benatia commented 2 years ago

Hi, I am using feathers-mongoose version 8.5.1 , mongoose 6.0.13, I am installing 'mongoose-lean-virtuals' and the lean attribute that we should pass in order to support that is lean: {virtuals: true}, which does not align with the code in this repo - which demands lean to be boolean.

The thing is that this actually make it work - my question is: how come ? I presume feathers just pass that to mongoose which support that ( with the plugin of course ).

is it true? if so - the documentation and code and options types should support that.

DaddyWarbucks commented 2 years ago

This makes sense. You can see here https://github.com/feathersjs-ecosystem/feathers-mongoose/blob/dc24ee43a54f15b2b8d015d8e26180801ad8afb9/lib/service.js#L68 that feathers-mongoose does pass whatever value you provide to lean. So the types could be updated, but I believe that will be difficult to nail down all of the potential options and will likely just be an any.

Also, the feathers way to handle virtuals is via hooks. Checkout Feathers Schema or withResult

DaddyWarbucks commented 2 years ago

Furthermore, the lean option should be used per service call in params. I believe this is how some other database adapters work, such as sequelize raw. So the service should default to whatever lean option the service is created with, but you can also override it with params

// This would work, but we would have to pluck `lean` off
// the mongoose param before passing to the underlying method
app.service('posts').find({ mongoose: { lean: false } });

// Don't put in mongoose param, make it a vanilla param.
// This would also work and us not have to pluck it off
// of params.mongoose, but its just kinda lonely
app.service('posts').find({ lean: false });