Applet Cloud Development - Cloud function operation data table function integration

Cloud applet integration operation function data table deletions

If the cloud is not a function of the use of official position, can integrate data table operations like it, saved several locations

The main number is read infrequent table can use this method.

// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
  env: '你的云环境id'
})
const db = cloud.database()
// 云函数入口函数
exports.main = async(event, context) => {
  //集合数据增加操作
  var opr = event.opr;
  if (opr == 'add') {
    //参数列表: 集合名 上传的数据对象
    try {
      return db.collection(event.tablename).add({
        data: event.data
      })
    } catch (e) {
      console.error(e)
    }
  } else if (opr == 'del') {
    //参数列表: 集合名 删除的元素docid
   // console.log(typeof event.docid == 'undefined')
    
      //条件删除有一些问题 需要修改测试一下下
      //console.log(event.belongs)
      console.log(event.id)
      try {
        return await db.collection(event.tablename).doc(event.id).remove()
      } catch (e) {
        console.error(e)
      }

  }
}

Guess you like

Origin www.cnblogs.com/masterchd/p/11886765.html