说我有三个模式
var Schema1 = new Schema({
field1: {type: String},
field2: {type: String},
subdocument: {type: SubDocumentSchema, ref: 'SubDocument'}
})
var Schema2 = new Schema({
field3: {type: String},
field4: {type: String},
subdocuments: {type: [SubDocumentSchema]}
})
var SubDocumentSchema = new Schema({
excludedField: {type: String},
field5: {type: String},
field6: {type: String},
})
现在让我们说我有一个名为objSchema1的Schema1类型的对象:
{
field1: "x",
field2: "y",
subdocuments: [
{
excludedField: "thisFieldIsntTested",
field5: "equalField",
field6: "equal"
},
{
excludedField: "thisFieldIsntTested",
field5: "nopeNotEqual",
field6: "equal"
},
]
}
以及Schema2集合中某处的Schema2类型的文档:
{
field3: "a",
field4: "b",
subdocuments: [
{
excludedField: "thisFieldIsntTested",
field5: "equalField",
field6: "equal"
},
{
excludedField: "thisFieldIsntTested",
field5: "notEqualThisTime",
field6: "equal"
},
]
}
我将如何执行如下查询:查找集合Schema2中的所有文档,其中每个子文档都等于obj1中的相应子文档(不包括excludedField
)?