ここに私のスキーマがあります:
var A = new Schema({
active: Boolean
, containers: [{
b: { type: ObjectId, ref: 'B' }
}]
})
var B = new Schema({
c: { type: ObjectId, ref: 'C' }
, d: { type: ObjectId, ref: 'D' }
})
var C = new Schema({ })
var D = new Schema({ })
基本的に、A
には への参照を持つコンテナの配列があり、 にB
は およびB
への参照がC
ありD
ます。
今、私は a の ID を持っており、 sによって使用されるC
セットが必要です。これは可能ですか?何らかの方法でスキーマを変更する必要がありますか?D
active
A
編集:ここに実際のスキーマ
//Mashup has a number of Containers (containerSchema is a sub-doc)
//so that the same Component could belong to two different Containers
var containerSchema = new Schema({
pos: { top: Number, left: Number }
, size: { width: Number, height: Number }
, component: { type: ObjectId, ref: 'Component' }
})
var mashupSchema = new Schema({
name: String
, desc: String
, size: { width: Number, height: Number }
, active: Boolean
, containers: [containerSchema]
})
//I am using 'mongoose-schema-extend' to inherit from componentSchema (waiting for the new PR)
var componentSchema = new Schema({
name: String
, desc: String
}, { collection : 'components', discriminatorKey : '_type' })
//now the various components
var imageComponentSchema = componentSchema.extend({
url: String
})
var textComponentSchema = componentSchema.extend({
text: String
})
var htmlComponentSchema = componentSchema.extend({
html: String
})
//this particular component needs a page and a selector
//(which could live outside it and belong to multiple components)
var webComponentSchema = componentSchema.extend({
page: { type: ObjectId, ref: 'Page' }
, selector: { type: ObjectId, ref: 'Selector' }
})
var pageSchema = new Schema({
name: String
, desc: String
, url: String
, active: { type: Boolean, default: false }
})
var selectorSchema = new Schema({
desc: String
, url: String
, cssPath: String
})
///MODELS
var Mashup = mongoose.model("Mashup", mashupSchema)
var Component = mongoose.model("Component", componentSchema)
var ImageComponent = mongoose.model("ImageComponent", imageComponentSchema)
var TextComponent = mongoose.model("TextComponent", textComponentSchema)
var HtmlComponent = mongoose.model("HtmlComponent", htmlComponentSchema)
var WebComponent = mongoose.model("WebComponent", webComponentSchema)
var Page = mongoose.model("Page", pageSchema)
var Selector = mongoose.model("Selector", selectorSchema)