【问题标题】:loopback 3 string not matched with and condition环回 3 字符串与和条件不匹配
【发布时间】:2019-07-17 14:12:12
【问题描述】:

我正在尝试在环回 3 中使用多个值进行过滤。“AND 条件”不起作用。数值过滤器运行良好,但字符串值不匹配。

这是我现在的状态:

{ "and": [{ "id": { "neq": "5d146f1f7a62651b8162fcf3" } }, 
{ "gender": "male" }, { "age": { "between": [16, 60] } }, 
{ "interestId": { "inq": ["5d11c0ce59e2b64e8dc12956", "5d11c0e259e2b64e8dc12958", "5d11c08659e2b64e8dc12953", "5d11c01759e2b64e8dc1294b", "5d11c03759e2b64e8dc1294d"] } }, 
{ "location": { "near": { "lat": 26.8574194, "lng": 75.7977288 }, "maxDistance": 6, "unit": "kilometers" } },
  { "maritalStatus": { "like": {} } }, { "college": { "like": {} } },
  { "career": { "like": {} } }, { "currentJob": { "like": {} } }, 
  { "height": { "between": [50, 89] } }, { "weight": { "between": [72, 192] } }, { "bodyBuild": "Slim" }] }

字符串值没有压入数组。

if (interestId.highSchool && interestId.highSchool !="") {
          var highschool = new RegExp('.*' + interestId.highSchool + '.*', "i");
          query.and.push({
            highSchool: { like: highschool }
          })
        }

我不明白的问题在哪里。如果我没有传递字符串值,它工作正常。

【问题讨论】:

    标签: regex mongodb loopback


    【解决方案1】:

    尝试以下方式:-

    if (interestId.highSchool && interestId.highSchool !="") {      
      query.and.push({
         highSchool: {regexp: new RegExp('.*' + interestId.highSchool + '.*', "i")}
      })
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-24
      • 2015-12-23
      • 2011-04-28
      • 1970-01-01
      相关资源
      最近更新 更多