// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
//!!!!!!!定义db一定要写在exports外面
const db = cloud.database()
// 云函数入口函数
exports.main = async(event, context) => {
//!!!!!!!await可使数据库更新
return await db.collection("Users").where({
number: "123",
password: "123"
}).get().then(res=>{
return res
}).catch(err=>{
return err
})
}
注意:
1、定义db=clound.database()一定要写在exports外面(不写wx.clound.database())
2、await关键字可使数据库实时更新
3、云端操作数据库要用promise写法(.then .catch), success、fail的回调函数写法只在小程序端适用