自定义查询猫鼬

时间:2019-10-16 20:24:02

标签: json mongodb mongoose

我尝试对MongoDB进行自定义查询。我知道查询是JSON,但我可以在查询中添加任何语句。我喜欢在查询中添加“ plaats”。此示例不起作用,但我不知道如何更改

 exports.fetch = function(req, res, next) {
  const {
    types,
    plaats
  } = req.body;
  let query = {
    types: {
      $elemMatch: {
        catid: {
          $in: types
        }
      }
    }
  }
  if (plaats) {
    query.location = {city : plaats};
  }
  ItemsOnline.find(query, function(err, items) {
    if (err) {
      console.log(err);
      //return next(err);
    }
    shuffle(items);
    res.json({
      items
    });
  });
};

0 个答案:

没有答案