Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

mongoose search combine fields

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",
      },
    },
  },
]);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #mongoose #search #combine #fields
ADD COMMENT
Topic
Name
8+3 =