Database.RegExp

创建云数据库的相关指令所需的正则表达式对象

参数

名称 类型 必须 说明
data Object
data.regexp String 正则表达式
data.options String 正则表达式 flags: i, m, s

返回值

RegExp

代码示例 1

const cloud = require('swan-server-sdk')
exports.main = async (event, context) => {
  cloud.init(context)
  const db = cloud.database()
  try {
      return await db.collection('articles').where({
        title: /miniprogram/i,
    })
  }
  catch(err) {
    console.log(err)
  }
}

代码示例 2

const cloud = require('swan-server-sdk')
exports.main = async (event, context) => {
  cloud.init(context)
  const db = cloud.database()
  try {
      return await db.collection('articles').where({
        title: db.RegExp({
            regexp: '^baidu',
            options: 'i',
        }),
    })
  }
  catch(err) {
    console.log(err)
  }
}

代码示例 3

const cloud = require('swan-server-sdk')
exports.main = async (event, context) => {
  cloud.init(context)
  const db = cloud.database()
  try {
      return await db.collection('articles').where({
        title: new db.RegExp({
            regexp: '^baidu',
            options: 'i',
        }),
    })
  }
  catch(err) {
    console.log(err)
  }
}