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 and .populate together #1260

Closed
kof opened this issue Dec 25, 2012 · 18 comments
Closed

.lean and .populate together #1260

kof opened this issue Dec 25, 2012 · 18 comments

Comments

@kof
Copy link

kof commented Dec 25, 2012

Is there any way or any plans to make them usable together?

Are there any issues which make it difficult to implement?

P.S. I am now using .lean in the most places, because I spent a huge amount of cpu time on wrapping in mongoose documents.

@aheckmann
Copy link
Collaborator

Not right now but that makes good sense. If the query was lean the
populated documents should be lean too.

I'm rewriting the populate code right now so I'll add this to the TODO list.

On Tuesday, December 25, 2012, Oleg Slobodskoi wrote:

Is there any way or any plans to make them usable together?

Are there any issues which make it difficult to implement?

P.S. I am now using .lean in the most places, because I spent a huge
amount of cpu time on wrapping in mongoose documents.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1260.

Aaron
@aaronheckmann https://twitter.com/#!/aaronheckmann

@kof
Copy link
Author

kof commented Dec 28, 2012

Сurrently .populate has no effect at all

@aheckmann
Copy link
Collaborator

eww. ok thanks.

@jameswyse
Copy link

👍 I ran in to this today as well, adding .lean() cancels out .populate().

@hannesgassert
Copy link

+1

@aheckmann
Copy link
Collaborator

fixed here (populate-wip branch) 8f7dda9

@hannesgassert
Copy link

Thanks for fixing this one! What release will the fix be in, 3.5.5?

@aheckmann
Copy link
Collaborator

3.6

aheckmann added a commit that referenced this issue Jan 14, 2013
aheckmann added a commit that referenced this issue Jan 30, 2013
aheckmann added a commit that referenced this issue Jan 31, 2013
aheckmann added a commit that referenced this issue Feb 2, 2013
aheckmann added a commit that referenced this issue Feb 3, 2013
@yarrouye
Copy link

Is it really fixed? I just got the master, installed its dependencies, and lean() and populate() don't seem to work together: I see { "_id": "......", "_bsontype": "ObjectId" } and not the field I wanted.

aheckmann added a commit that referenced this issue Mar 2, 2013
@aheckmann
Copy link
Collaborator

@yarrouye all the tests are passing. can you open a new ticket with steps to reproduce?

@markreg
Copy link

markreg commented Aug 20, 2013

I know that this issue has been solved, however, I'm not quite sure why it's intuitive to use .lean() before .populate(). It makes sense for me to .populate() before.lean() so that the document get's populated and then .toObject()ed. Can anyone please explain so that I'm sure that I haven't misunderstood the purpose of .lean()?

@aheckmann
Copy link
Collaborator

lean skips all the overhead of creating mongoose documents from the objects returned by the driver and just returns them as is. performance win.

@markreg
Copy link

markreg commented Aug 20, 2013

But didn't .populate() used to work with .lean() if populate was called before lean?

@aheckmann
Copy link
Collaborator

in < 3.6, if lean was used, population wouldn't occur.

@markreg
Copy link

markreg commented Aug 20, 2013

Oh, so the order of lean and populate calls didn't matter? I didn't realize that.

@aheckmann
Copy link
Collaborator

populate() just sets an option, same as lean()

@mallikarjunece
Copy link

How to use lean and populate together ?

@Automattic Automattic locked as resolved and limited conversation to collaborators Sep 4, 2019
@vkarpov15
Copy link
Collaborator

@mallikarjunece If you set lean() on your query like Model.find().lean().populate('myPath'), lean() will also apply to the populated docs.

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

No branches or pull requests

8 participants