这是我的模型:
var LocationSchema = new Schema(
{
events: [
{
type: mongoose.Schema.Types.ObjectId,
ref: 'Event'
}
]
})
var EventSchema = new Schema(
{
title : String,
location: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Location'
}
})
我想从Location模型中查询Event模型内的一个字段。
以下查询无法实现。
findOne({events: {$elemMatch: {title: 'test'}}})
我不确定是否有可能将其实现...
.filter()
。 - Blakes Seven