Database.RegExp

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

参数

名称类型必须说明
dataObject
data.regexpString正则表达式
data.optionsString正则表达式 flags: i, m, s

返回值

RegExp

代码示例 1

  1. const cloud = require('swan-server-sdk')
  2. exports.main = async (event, context) => {
  3. cloud.init(context)
  4. const db = cloud.database()
  5. try {
  6. return await db.collection('articles').where({
  7. title: /miniprogram/i,
  8. })
  9. }
  10. catch(err) {
  11. console.log(err)
  12. }
  13. }

代码示例 2

  1. const cloud = require('swan-server-sdk')
  2. exports.main = async (event, context) => {
  3. cloud.init(context)
  4. const db = cloud.database()
  5. try {
  6. return await db.collection('articles').where({
  7. title: db.RegExp({
  8. regexp: '^baidu',
  9. options: 'i',
  10. }),
  11. })
  12. }
  13. catch(err) {
  14. console.log(err)
  15. }
  16. }

代码示例 3

  1. const cloud = require('swan-server-sdk')
  2. exports.main = async (event, context) => {
  3. cloud.init(context)
  4. const db = cloud.database()
  5. try {
  6. return await db.collection('articles').where({
  7. title: new db.RegExp({
  8. regexp: '^baidu',
  9. options: 'i',
  10. }),
  11. })
  12. }
  13. catch(err) {
  14. console.log(err)
  15. }
  16. }