users: 当前云开发中数据库的表,即为用户表
login: 云开发中的云函数
// 引入数据库
const db = wx.cloud.database()
Page({
demo () {
// 在数据库中写入url、name 两条信息
db.collection('users').add({
data: {
url: 'http://url.com',
name: 'jack',
}
}).then(res => {})
// 读取表中的信息
db.collection('users').doc(res._id).get().then(res => {
//信息的读取
console.log(res, '从数据库中读取到的信息')
}
})
// 调用云函数, 如update更新函数,
// 更新users表中的num字段为6
wx.cloud.callFunction({
name: 'update',
data: {
collection: 'users',
doc: id,
data: {
num: 6
}
}
}).then(res => {
console.log(res)
})
// 查询 where
// 查询 _openid等于res.result.openid的结果
db.collection('users').where({
_openid: res.result.openid
}).get().then(res => {
console.log(res)
})
//更新表中的信息 update
// 更新表中的signature字段
db.collection('users').doc(app.userInfo._id).update