我有兩個模式如下:
const castListSchema = new Schema({
id: String,
roleInVideo: String
});
const videoSchema = new Schame({
castList: { type: [castListSchema], default: [] }
});
我想通過以下結構獲取資料:
castList: [
{
details: { ... },
roleInVideo: 'director'
},
...
]
我想不使用virtual
等等aggregate
...
可能嗎?如何?
uj5u.com熱心網友回復:
是的,您可以在物件陣列中使用虛函式。
使用以下代碼將虛函式用于物件陣列。
videoSchema.virtual("castList.castData", {
ref: "new_assets",
localField: "castList.castListSchema",
foreignField: "_id",
justOne: true
});
在填充中也使用這個“castList.castData”作為檢索資料的鍵。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/487241.html
標籤:javascript mongodb 猫鼬 图式 猫鼬模式
上一篇:Mongodb-如何在生成的嵌入檔案中對不同的欄位進行分組
下一篇:mongo-在過濾時訪問鍵值欄位