小程序云开发——云函数批量删除集合数据2020-07-28

云函数

1.云函数入口文件

const cloud = require('wx-server-sdk')

cloud.init({

  env: "shenpei-4agzp"

})

const db = cloud.database();

// 云函数入口函数

exports.main = async (event, context) => {

  try {

    return await db.collection('list').where({

      checked: false   //"checked"数据字段,"false" 值   

    }).remove()

  } catch (e) {

    console.error(e)

  }

}

index.js

  batchDelete: function() {

    wx.cloud.callFunction({

      name: 'shangchu'

    }).then(res => {

      console.log(res)

    }).catch(err => {

      console.log(err)

    })

  }

index.wxml

<button type='primary' bindtap="batchDelete">清空数据</button>

项目链接: https://pan.baidu.com/s/1uz_Eiz148Ya1e1_APT7NBg 提取码: 5etp

PS 有问题可以联系WX:qiaominliu

猜你喜欢

转载自blog.csdn.net/weixin_44495982/article/details/107642357