I have a Mongoose schema with an array lists of objects that consist of a reference to another collection and a nested array of numbers:
var Sch
// Cart schema
var CartSchema = new mongooseSchema({
productDetails: [
{
productId: {
type: mongoose.Schema.ObjectId,
required: true,
ref:'Product'
},
productCount: Number,
}
],
UserId: {
type: String,
default: '',
required: true,
trim: true,
},
shopId: {
type: String,
default: '',
required: true,
trim: true,
},
});
// add this .populate('productDetails.productId').
db.Cart.find({
UserId: userId,
shopId: shopId
}).populate('productDetails.productId').skip(pagination.skip).limit(pagination.limit).exec(function (error, CartList) {
if (error) {
callback(error, null)
} else {
callback(null, CartList)
}
});