let Schema = mongoose.Schema
let simpleSchema = new Schema({
company: { type: Schema.Types.ObjectId, ref: 'Company', require: true }
....
})
并且此架构没有anotherSchema
引用。但是anotherSchema
有simpleSchema
引用
let anotherSchema = new Schema({
simple: { type: Schema.Types.ObjectId, ref: 'Simple', require: true }
....
})
所以当我从第一个模式创建模型时
return mongoose.model('Simple', simpleSchema)
我称之为:
simpleSchema.statics.testpopulate = function (id) {
return this.findOne()
.where('_id').equals(id)
.populate('company')
.populate('simple')
.then((s) => {
console.log('sc', s.company)
console.log('sp', s.simple)
return Promise.resolve(s)
}).catch((err) => {
return Promise.reject(err)
})
}
它只记录公司。我知道这是对的,但我怎么能强迫回归呢?
所以我想要检索所有引用我的简单集合的对象