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 across multiple levels #119

Closed
mcnamee opened this issue Sep 1, 2016 · 2 comments
Closed

$populate across multiple levels #119

mcnamee opened this issue Sep 1, 2016 · 2 comments

Comments

@mcnamee
Copy link

mcnamee commented Sep 1, 2016

Hi,
Is it currently possible to populate across multiple levels via a rest URL get request?

For example, populating the friends array with user data:

const userSchema = new Schema({
   name: { type: String, default: '', required: true },
   friends: [
      { friendId: { type: String, ref: 'users' },
...

If not, any advice on how this could be achieved?

@adamh114
Copy link

adamh114 commented Sep 1, 2016

Assuming the users schema/model is registered, this works for me.

/service-name/?$populate[]=friends.friendId

I'll add that I've only done this when the field to populate is {type: Schema.Types.ObjectId}, so I'm not sure if it'll work with type String or not.

@mcnamee
Copy link
Author

mcnamee commented Sep 2, 2016

Ah ha, I didn't realise you could do square brackets deal. Thanks so much @adamh114

@mcnamee mcnamee closed this as completed Sep 2, 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