云数据库编写
基本方法编写
'use strict';
// 引用到云数据库
const db = uniCloud.database()
// 运行 在云端(服务器端)的函数
exports.main = async (event, context) => {
// 连接到数据库
const collection = db.collection('user')
//event为客户端上传的参数
// context 包含了调用信息和运行状态,获取每次调用的上下文
console.log('event : ', event)
//返回数据给客户端
return {
code:200,
msg:event.name + '的年龄是' + event.age,
context
}
}