変数の子モデルを参照する親モデルを持つ最良の方法を探しています。親モデルを保存するときに参照を設定し、子を自動的に設定する方法はありますか? そうでない場合、可変サブフィールドを持つ親モデルを実現する最良の方法は何ですか?
var ChildSchema1 = new Schema({
field1: String,
field2: String
});
var ChildSchema2 = new Schema ({
field3: Number,
field4: String
});
var ParentSchema = new Schema({
name: {type: String, required: true},
child_ref: {type: ObjectId, ref: ChildSchema1 OR ChildSchema2}
});