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