小编Vuk*_*kez的帖子

How to concat multiple fields in mongoose query?

I am trying to find() all docs with LIKE 'query.name' in concatenated fields instead of using $or to search in separated ones.

SQL query would be:

SELECT * FROM table WHERE column.name + ' ' + column.surname LIKE query.name
Run Code Online (Sandbox Code Playgroud)

This is the current code:

Model.find()
.and([
  {
    $or: [
      { name: new RegExp(req.query.name, 'i') },
      { surname: new RegExp(req.query.name, 'i') }
    ]
  },
  {
    $or: [
      { workPlace: new RegExp(req.query.place, 'i') },
      { location: new RegExp(req.query.place, 'i') }
    ]
  } …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js mongodb-query

6
推荐指数
1
解决办法
2097
查看次数

标签 统计

mongodb ×1

mongodb-query ×1

mongoose ×1

node.js ×1