📜  猫鼬搜索组合字段 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:31.393000             🧑  作者: Mango

代码示例1
db.collection.aggregate([
  {
    $addFields: {
      nameFilter: {
        $concat: ["$name", " ", "$surname"],
      },
      locationFilter: {
        $concat: ["$workplace", " ", "$location"],
      },
    },
  },
  {
    $match: {
      nameFilter: {
        $regex: req.query.name,
        $options: "i",
      },
      locationFilter: {
        $regex: req.query.place,
        $options: "i",
      },
    },
  },
]);