Mongoose - Populate on two dimensional array Mongoose - Populate on two dimensional array mongoose mongoose

Mongoose - Populate on two dimensional array


You need to specify the position of the subarray then populate the objects within:

Translation.findById(idTranslation).populate('translation.0.idVideo')

This would work for the first (subarray [0]), you would need to loop inside the array if you want to populate other subarrays, I don't think mongoose comes with any built in positional operator ($[] as in mongoDB native Client).
Example with a loop
Here is a full working example, I tried to mimic your schemas:

const fooSchema = new mongoose.Schema({    name: String  });const Foo = mongoose.model('Foo', fooSchema);const barSchema = new mongoose.Schema({    x: String,    y: String,    fooId: {      type: mongoose.Schema.Types.ObjectId,      ref: 'Foo'    }  });const Bar = mongoose.model('Bar', barSchema);const totoSchema = new mongoose.Schema({    bar: [[barSchema]]  });const Toto = mongoose.model('Toto', totoSchema);// seedslet foo = new Foo({name: 'foo'});let bar, bar2;foo.save().then(val => {  bar = new Bar({x: '1', y: '1', fooId: val._id});  bar2 = new Bar({x: '2', y: '2', fooId: val._id});  toto = new Toto({bar: [[bar, bar2], [bar, bar2]]}).save(); // pushing the same objects(bar and bar2) out of lazyness});// A find query with a loop to construct paths to be populated  Toto.findById(/* totoId */)    .exec()    .then(toto => {      let arr = [];      for(let i = 0; i <= toto.bar.length; i++) { // length of the array (1st dimension)        arr.push(`bar.${i}.fooId `); // constrtucting the path      }      toto.populate(arr.join(''), (err, doc) => {        if(err) throw err;        else console.log(toto.bar);      });    })    .catch(err => console.log(err));/* Output[  [    {      "_id":"5cc472cd90014b60f28e6cb4",      "x":"1",      "y":"1",      "fooId":{"_id":"5cc472ca90014b60f28e6cb3","name":"foo","__v":0}    },     {      "_id":"5cc472cd90014b60f28e6cb5",      "x":"2",      "y":"2",      "fooId": {"_id":"5cc472ca90014b60f28e6cb3","name":"foo","__v":0}    }  ],   [    {      "_id":"5cc472cd90014b60f28e6cb4",      "x":"1",      "y":"1",      "fooId": {"_id":"5cc472ca90014b60f28e6cb3","name":"foo","__v":0}    },     {      "_id":"5cc472cd90014b60f28e6cb5",      "x":"2",      "y":"2",      "fooId": {"_id":"5cc472ca90014b60f28e6cb3","name":"foo","__v":0}    }  ]]*/

I hope this helps ;)