属于模式的对象的深度填充,该模式是 Mongoose 数组中对象的值。

Deep Population of an object that belongs to a Schema that is a value of an object in an array in Mongoose.

我有以下架构:

 const userSchema = new Schema({
    name: String,
    favoriteStreams: [
        {
            stream: {
              type: Schema.Types.ObjectId,
              ref: "Stream",
              unique: true
            },
            param: Number
        }
    ]
});

我这辈子都想不出如何填充每个流。此代码以及我尝试过的许多变体都不起作用。

User.findOne({_id: req.user._id})
       .populate({path: "favoriteStreams", populate: {path: "stream", model:"Stream"}})

增加的分离度让我很为难。我将如何获得每个流属性?

这个怎么样:

User.findOne({_id: req.user._id})
.populate(path: "favoriteStreams.stream")