• 云函数(能够了解为一般开发中的接口的实现)
  1. cloudfunctions目录右键新建node.js云函数例如helloWord
  2. 须要在终端里 去装置云函数helloWord
cd cloudfunctions/helloWordnpm i
  1. 装置实现后,这时的云函数就是能够应用了(函数的内容是用户的根本信息)。
  2. 能够在小程序index.jsonload生命周期里去调试应用一下(调用云函数就像是调用接口)。
const result = await wx.cloud.callFunction({    name:'helloWord'})console.log(result)
  • 应用云函数进行数据库的查问和批改
  1. 数据库反对async/await操作
  2. 在进行数据库add时 须要新建一个数据库汇合(表)也无需定义表构造
  3. db.collection 能够进行表的查问操作
  4. db.command 能够进行简单的子表查问
  5. .where 前面跟查问条件
  6. .get 是查问后果
const db = wx.cloud.database() await db.collection('users').where({  _openid: 'user-open-id'}).get({  success: function(res) {    console.log(res.data)  }})