[英]MongoDB / Mongoose has many Relationship
因此,我试图找出Mongo / Mongoose中的人口和人际关系。 我有一个将会有很多预测的灯具。 如果我想显示预测的指标,我可以简单地使用填充方法,但是如果我需要显示预测的所有指标怎么办?
这听起来很简单,但是也许我仍然想弄清楚我的SQL头。 这是容易做到的吗,还是我以错误的方式来对待它? 这是我的模特-
var FixtureSchema = new Schema({
homeTeam: {
type: Number,
required: true,
ref: 'Team'
},
awayTeam: {
type: Number,
required: true,
ref: 'Team'
},
date: {
type: Date
},
matchday: {
type: Number,
required: true
}
});
var PredictionSchema = new Schema({
goalsHomeTeam: {
type: Number,
required: true
},
goalsAwayTeam: {
type: Number,
required: true
},
fixture: {
type: Number,
ref: 'Fixture'
},
user: {
type: Schema.ObjectId,
ref: 'User'
}
});
您将必须首先找到所需的灯具,然后搜索您的预测并找到匹配项。 Mongo没有“反向”人口,但是编写自己的东西很容易:
Prediction.find({fixture: fixture._id}, function(err, predictions) {
//do things with predictions
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.