微信小程序 云开发 云函数创建及应用微信官方文档
链接数据库
const cloud
= require('wx-server-sdk')
cloud
.init({
env
:"text-modle-t3tox"
})
const db
= cloud
.database()
对数据进行操作(以添加为例)
注意:在云函数中是可以进行多条插入的用传递过来的参数进行赋值⬅⬅⬅⬅
exports
.main
= async (event
, context
) => {
let result
= await db
.collection('test')
.add({
data
: [{
name
: '张三',
category
: 'fruit1',
price
: 101,
},{
name
: '李四',
category
: 'fruit2',
price
: 102,
}]
})
return {
result
}
}
注意:书写完成后一定要再次上传云函数
调用云函数
async development(){
let res
= await wx
.cloud
.callFunction({
name
:"ceshi"
})
console
.log(res
)
},
结果展示:
转载请注明原文地址:https://ipadbbs.8miu.com/read-25094.html