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

Populating an Array of ObjectIds Not Working #379

Open
johnmastri opened this issue May 22, 2018 · 3 comments
Open

Populating an Array of ObjectIds Not Working #379

johnmastri opened this issue May 22, 2018 · 3 comments
Labels

Comments

@johnmastri
Copy link

First off, great library - thank you.

I have defined two schemas:

const RoutineSchema = new mongoose.Schema({
    name: {type: String},
    description: {type: String},
});

const UserSchema = new mongoose.Schema({
    name: { type: String, required: true },
    first_name: { type: String },
    last_name: { type: String },
    facebook_id: { type: String },
    email: { type: String },
    routines: { type: [Schema.ObjectId], ref:"Routine" },
});

when I hit api/v1/User?populate=routines I'm ending up with an empty array for routines. When I leave off ?populate=routines, it returns the ObjectIds as expected in the array. Is this possible with the current library?

@dwoodard
Copy link
Contributor

dwoodard commented Jun 5, 2018

Populate is case sensitive with regards to your example routine. Ensure routines is lowercased in your DB and in your UserSchema routines ref.

This:
routines: { type: [Schema.ObjectId], ref:"routine" },
vs
routines: { type: [Schema.ObjectId], ref:"Routine" },

@dwoodard
Copy link
Contributor

dwoodard commented Jun 5, 2018

#381

@Zertz Zertz added the question label Jun 9, 2018
@Zertz
Copy link
Collaborator

Zertz commented Jun 9, 2018

Sounds right, thanks for the help @dwoodard !

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

No branches or pull requests

3 participants