Ich schreibe diese Frage und die Antwort in der Hoffnung, es wird jemand anderem helfen (oder wenn es eine bessere Antwort gibt).Mongoose subschema array virtuals
Wie erstelle ich virtuals für Mongoose geschachtelte Schemas, wenn in Array-Form?
Hier sind die Schemata:
var Variation = new Schema({
label: {
type: String
}
});
var Product = new Schema({
title: {
type: String
}
variations: {
type: [Variation]
}
});
Wie ich eine virtuelle auf variations
möchte. Es scheint, dass, wenn die Unter doc kein Array ist, dann können wir einfach tun:
Product.virtual('variations.name')...
Aber das funktioniert nur für nicht-Arrays.