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 doesn't work? #21

Open
Oleg2tor opened this issue Jan 30, 2014 · 3 comments
Open

Populate doesn't work? #21

Oleg2tor opened this issue Jan 30, 2014 · 3 comments
Assignees
Labels

Comments

@Oleg2tor
Copy link

var ComponentSchema = new Schema({
    'page': {type: ObjectId, ref: 'Page'},
    'user': {type: ObjectId, ref: 'User'},
    'priority': {type: Number, default: 0}
}, { collection : 'components', discriminatorKey : '_type' });

var GallerySchema = ComponentSchema.extend({
    'images': [{type: ObjectId, ref: 'Image'}],
});

var ImageSchema = new Schema({
    'priority': {type: Number, default: 0},
    'file': {type: String, default: ''},
    'name': {type: String, default: ''},
    'title': {type: String, default: ''}
});

mongoose.model('Component', ComponentSchema);
mongoose.model('Gallery', GallerySchema);
mongoose.model('Image', ImageSchema);

When I run:

Component.find({
    "page": page._id
})
.populate('images')
.sort({
    "prirority": 1
})
.exec(function (err, components) {
    console.log(components);
});

I get empty array:

{ __v: 1, _id: 52e908cdf0b7745822000026, _type: 'Gallery', images: [], page: 52e6a4e554c4da2c1200005f, user: 52c18a0d647816701e000002, priority: 0 }

If I use "Galley.find({" instead of "Component.find({" - I get right result of populating.

@mbatista
Copy link

+1

@mbatista
Copy link

Any chance of this being fixed?

@sieira
Copy link
Collaborator

sieira commented Nov 11, 2015

Will check it soon

@sieira sieira added the bug label Nov 11, 2015
@sieira sieira self-assigned this Nov 11, 2015
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