Populate Object with an Object in array of arrays with MongoDB + Node.js

411 Views Asked by At

I want to populate an object in my Schema with an object inside array of arrays So I need to check two IDs. One for each array.

{ _id: 101,
NewsGroup: [ [_id: 102, category: A], [_id: 103, category: B] ] }

I want to populate an object called Alpha with category: A

When I try this:

Model.findById(101).populate('Alpha', 'NewsGroup.category').exec(function(err, Beta) {
    req.Zita = Beta ;
    console.log( Zita );
});

It returns all categories Not only A.

I have tried this as well But it does not work

.populate({
           path: 'Alpha',
           match: { 'NewsGroup':  { '_id': '102' } },
           //match: { 'NewsGroup':  { $elemMatch: { '_id': '102' }}  },
           select: 'category'
        })

Any Ideas?

0

There are 0 best solutions below