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

lean is not correct in documentation and actual behavior #427

Open
dor-benatia opened this issue Mar 29, 2022 · 2 comments
Open

lean is not correct in documentation and actual behavior #427

dor-benatia opened this issue Mar 29, 2022 · 2 comments

Comments

@dor-benatia
Copy link

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
Copy link

DaddyWarbucks commented Mar 29, 2022

This makes sense. You can see here

const q = model.find(query).lean(this.lean);
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
Copy link

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 });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants