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

Populate with Mongoose #284

Open
Gyurmatag opened this issue Dec 23, 2020 · 2 comments
Open

Populate with Mongoose #284

Gyurmatag opened this issue Dec 23, 2020 · 2 comments

Comments

@Gyurmatag
Copy link

Hi!

How can I Populate my nested objects with Mongoose?

Thank you for your answer!

@rfreebern
Copy link

I'm unfamiliar with mongoose, but I think you should be able to call populate on the result within the pagination function. Can you post a snippet of code that you're not having luck with?

@Gyurmatag
Copy link
Author

I managed to get it working by doing this.
In this function I am fetching some quotes and populating it with the character details who said the quote:

const quotes = async (_, { limit, next }) => {
  return Quote.paginate({ limit: limit, next: next })
    .then((data) => {
      data.results = data.results
        .map(quote => Quote.populate(quote, [{ path: 'character' }]))
      return data
    })
}

Is this a good, optimized solution? If not, how can I manage to solve this in an optimized way?

Thank you for the answers in advance!

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