Mongoose Middleware:人口密钥

时间:2015-03-20 15:08:37

标签: node.js mongodb express mongoose meanjs

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

我想在Moongose Middleware keyword option字段中搜索字词: tags.text description spot.name < / p>

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

对于字段 tags.text description 正在运行。

但该领域&#34;现场&#34;是一个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);


        }
    });

1 个答案:

答案 0 :(得分:0)

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

首先,我使用单词搜索 Spot ,然后使用这样的过滤器搜索训练

exact:{spot: spotThatIFoundId}