我想用我的架構上的外鍵連接多個視頻
@Prop({
type: mongoose.Schema.Types.ObjectId,
ref: Video.name,
})
videos: Video[];
順便說一句,結果沒有回傳 Array。我正在回傳 1 個視頻(外鍵)。
videos: "xxxxxx"
我想要以下結果
videos: ['xxxx', 'rrrr', 'yyyyy', ...]
我該如何解決這個問題?
uj5u.com熱心網友回復:
您可以輕松解決此問題。
@Prop({
type: [
{
type: mongoose.Schema.Types.ObjectId,
ref: Video.name,
autopopulate: true,
},
],
})
videos: Video[];
您必須將型別定義為模式中的陣列。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/432401.html
