原文:https://blog.csdn.net/qq_29384639/article/details/97150340
解釋:
db.RegExp
從基礎庫 2.3.2 開始(wx-server-sdk 從 0.0.23 開始),數據庫支持正則表達式查詢,開發者可以在查詢語句中使用 JavaScript 原生正則對象或使用 db.RegExp 方法來構造正則對象然后進行字符串匹配。在查詢條件中對一個字段進行正則匹配即要求該字段的值可以被給定的正則表達式匹配
事例:
search(e, val) { const _this = this this.screenName = e const db = wx.cloud.database({env: '環境ID'}) const _ = db.command db.collection('person').where(_.or([ { name:db.RegExp({ regexp:e, option:'i' }) }, { person:db.RegExp({ regexp:e, option:'i' }) }, { location:db.RegExp({ regexp:e, option:'i' }) } ]).and([{ del:0 }])).get({ success: function(res) { _this.list = res.data } }) },
上面.or中條件為或,.and條件中並列滿足。