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 documentation #75

Closed
ansarizafar opened this issue Apr 15, 2016 · 1 comment
Closed

$populate documentation #75

ansarizafar opened this issue Apr 15, 2016 · 1 comment

Comments

@ansarizafar
Copy link

@ekryski I think $populate is not documented anywhere. I only want few specific fields returned for the populated documents. I can do this with Mongoose like this

Story
.findOne({ title: /timex/i })
.populate('_creator', 'name') // only return the Persons name
.exec(function (err, story) {
  if (err) return handleError(err);

  console.log('The creator is %s', story._creator.name);
  // prints "The creator is Aaron"

  console.log('The creators age is %s', story._creator.age);
  // prints "The creators age is null'
})

I am using this code with feather client

customerService.find({query: { _id: '570e865e181048f80e87164d',  $populate: ['area'], $select: ['name','email','area']}}).then(customer => {
      this._customer = customer;
      console.log(customer);
   });

How can I only return name field from area service?

@ekryski
Copy link
Member

ekryski commented Apr 21, 2016

@ansarizafar currently you'd have to do that in a hook or a series of hooks. Right now the query syntax doesn't support applying special query params to populated models.

In all honesty we are currently working out the best way to handle this. This is one of the strengths of GraphQL so we are evaluating that to see if it makes more sense to lean on GQL instead of adding this functionality ourselves. Stay tuned for that!

In the mean time you need to use a server side hook if you want to reduce what is returned from the server. If you are just trying to normalize the response for your client side code (say a component only getting what it needs) you can add a client side after hook for the find method on your customerService.

I'm going to close this, but feel free to comment if that doesn't make sense. I think in reality this actually a couple different issues that still need to be figured out. Thanks for asking @ansarizafar!

@ekryski ekryski closed this as completed Apr 21, 2016
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