我在查询时很疯狂,根据引用的文档属性查找匹配项.我已经定义了这样的架构:
mongoose.model('Route', new mongoose.Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
}
}));
mongoose.model('Match', new mongoose.Schema({
route: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Route'
}
}));
Run Code Online (Sandbox Code Playgroud)
因此,当我在Match模型中搜索来自特定用户的路线时,我会做类似的事情(也尝试没有'_id'属性):
match.find({'route.user._id': '53a821577a24cbb86cd290d0'}, function(err, docs){});
Run Code Online (Sandbox Code Playgroud)
但不幸的是,它没有给我任何结果.我也尝试填充模型:
match.find({'route.user._id': '53a821577a24cbb86cd290d0'}).populate('route').exec(function(err, docs){});
Run Code Online (Sandbox Code Playgroud)
但这并没有什么不同.我知道的解决方案(但不认为它们是最好的):
有人建议吗?提前谢谢了!
相关问题(但不是提供的工作解决方案):