Mongoose Middleware:带人口的关键字

Mongoose Middleware: Keyword with population

我在 MEAN.JS 应用程序中使用 Mongoose 中间件进行搜索。

我想为字段搜索 Moongose Middleware keyword option 的单词:tags.textdescriptionspot.name

filters = {
   filters : {
     mandatory : {
           exact : { 
             municipality: mongoose.Types.ObjectId(req.user.municipality.id)
             }
      },
     keyword : { 
           fields: ['tags.text','description','spot.name'],
           term:word
           }
      }
 };

对于字段 tags.text描述 有效。

但是字段 "spot" 是一个 ObjectID,而不是文档字段,我正在做一个填充,它正在工作,但不工作字段 spot.name 在关键字选项中...

有什么建议吗?

Training
    .find()
    .sort('-created')
    .populate({path: 'spot', select: 'name image likes location'})
    .populate({path: 'user', select: 'displayName imageProfile'})
    .populate('municipality','name')
    .populate('country','name')
    .field(options)
    .filter(filters)
    .keyword(filters)
    .page(pagination,function(err, trainings){
        if (err) {
            console.log(err);
            return res.status(400).send({
                message: errorHandler.getErrorMessage(err)
            });
        } else {
            res.jsonp(trainings);


        }
    });

也许这不是一个优雅的解决方案,但这是我目前找到的唯一解决方案。

首先,我用单词搜索了 Spot,然后,使用如下过滤器搜索了 Training

exact:{spot: spotThatIFoundId}