Skip to content

Are lean queries supported? #140

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

Closed
SnidelyWhiplash opened this issue Nov 12, 2018 · 6 comments
Closed

Are lean queries supported? #140

SnidelyWhiplash opened this issue Nov 12, 2018 · 6 comments

Comments

@SnidelyWhiplash
Copy link

As I understand it, queries return fully instantiated Mongoose models by default. But you can override this if you just need the raw data, and don't plan on calling any instance methods, etc by using the lean option...

In my (limited) testing, it doesn't seem like that is supported in resolvers here..? I've tried both Model.find({ query }, null, { lean: true }) and Model.find({ query }).lean() but it seems to prevent me from querying relational data. (It's been a while since I tested, I'm only just now circling back to this. I can provide fuller examples/errors if needed).

In the past, on REST projects, I've noticed significant performance impacts when querying for multiple documents without lean, and in my current GraphQL project I'm thinking this may also be the reason for slow query times.

Thanks for any insight!

@SnidelyWhiplash
Copy link
Author

Is there any input on this please? cc @nodkz ?

@nodkz
Copy link
Member

nodkz commented Dec 4, 2018

@SnidelyWhiplash sorry for late response. I was terribly busy with preparation for 2 conference talks and 2 active projects.

Let think what we can do with lean:

Thanks! Hope this problem is still actual for you.

@SnidelyWhiplash
Copy link
Author

Hi @nodkz. This reply is incredibly delayed, sorry for that! We moved on to other issues, but now we're revisiting this.

I'll try to open a PR with a test, but I was curious if perhaps there has already been any movement on this feature? If my understanding is correct, using .lean(), especially when querying for multiple documents, is significantly faster than not (anywhere from 3 - 10 times faster).

Thanks!

references:
https://www.tothenew.com/blog/high-performance-find-query-using-lean-in-mongoose-2/
https://mongoosejs.com/docs/tutorials/lean.html

@jdbdnz
Copy link

jdbdnz commented Jun 16, 2020

@SnidelyWhiplash I found a workaround. Albeit not perfect as it isn't a query option but instead specified during composition.

tc.getResolver('findMany').wrapResolve(next => resolveParams => next({
  ...resolveParams,
  beforeQuery: (query) => query.lean(),
}))

Check out this file for more context about how it works src/resolvers/helpers/beforeQueryHelper.js

@nodkz a perfect solution IMO would be to add lean as a resolver argument.

nodkz added a commit that referenced this issue Sep 5, 2020
…ean`, `findByOneLean` which returns data from DB without instantiating a full Mongoose documents. It's faster in several times but doesn't support getters & virtuals fields. See https://mongoosejs.com/docs/tutorials/lean.html#using-lean

Related #140
nodkz added a commit that referenced this issue Sep 5, 2020
…ean`, `findByOneLean` which returns data from DB without instantiating a full Mongoose documents. It's faster in several times but doesn't support getters & virtuals fields. See https://mongoosejs.com/docs/tutorials/lean.html#using-lean

Related #140
@nodkz
Copy link
Member

nodkz commented Sep 5, 2020

New lean-resolvers were added in 9.0.0-alpha.3.

@nodkz nodkz closed this as completed Sep 5, 2020
@nodkz
Copy link
Member

nodkz commented Sep 13, 2020

*Lean resolvers were removed in favor of { lean: true } config option in basic resolvers.

More details here: #263 (comment)

nodkz added a commit that referenced this issue Sep 13, 2020
nodkz added a commit that referenced this issue Sep 13, 2020
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

3 participants