MongoDB / Mongoose有很多关系

所以我试图找出在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' } }); 

你将不得不首先find你想要的夹具,然后search你的预测并find匹配。 Mongo没有“逆向”人口,但写你自己很容易:

 Prediction.find({fixture: fixture._id}, function(err, predictions) { //do things with predictions })