为啥我的单字段模糊查询可以,多字段模糊查询却不行?
发布于 6 年前 作者 minpeng 5081 次浏览 来自 问答

我在写模糊查询云函数FuzzySearch的时候,单字段模糊查询可以实现,但是换成多字段却报错什么都搜不到,有没有大神帮帮我

// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()

// 云函数入口函数
exports.main = async (event, context) => {
  //输入框的值
  let inputValue = event.inputValue;
  
  //单字段模糊查询 Information是数据库中集合 name和area是字段
  /**  return await db.collection('Information').where({
     name: db.RegExp({
       //从搜索栏中获取的value作为规则进行匹配。
       regexp: inputValue,
       //大小写不区分
       options: 'i',
     })
   }).get()*/

   //多字段模糊查询
  return await db.collection('Information').where(_.or([
    {
      name: db.RegExp({ 
        regexp: inputValue,
        options: 'i', 
      }),
    },
    {
      area: db.RegExp({
        regexp: inputValue,
        options: 'i',
      }),
    }
  ])).get()
}

1 回复

操作符没有定义

const _ = db.command
回到顶部