y***@163.com
y***@163.com
  • 发布:2021-08-31 00:39
  • 更新:2021-08-31 11:26
  • 阅读:717

uniCloud如何对字符串数组进行模糊查询?

分类:uniCloud

假设有如何格式的数据:

[  
  {  
    "_id": "a1",  
    "tags": [  
      "garden",  
      "theatre",  
      "open",  
      "online"  
    ]  
  },  
  {  
    "_id": "a2",  
    "tags": [  
      "share",  
      "save",  
      "option"  
    ]  
  },  
  {  
    "_id": "a3",  
    "tags": [  
      "new",  
      "document"  
    ]  
  }  
]

当我输入op时,我希望查询出a1、a2的数据,但我这样写时,查询会出错:

db.collection('xxx').where({ tags: dbCmd.elemMatch(new RegExp('op', 'gim')) }).get()

错误信息如下:
Error: errCode: DATABASE_REQUEST_FAILED | errMsg: [FailedOperation.Query] (BadValue) $elemMatch needs an Object

我该怎样写才能对字符串数组类型的字段做模糊查询呢?

2021-08-31 00:39 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

直接去掉elemMatch

  • y***@163.com (作者)

    一言惊醒梦中人,多谢啦

    2021-08-31 14:44

  • Javin

    回复 y***@163.com: 这个查询速度如何,是否把tags合并成一个string查询速度更快?

    2023-06-06 12:53

该问题目前已经被锁定, 无法添加新回复