云函数中数据记录的变更

云开发的数据

  • 局部更新
    更新数据
//点击更新数据
  updataData(){
    db.collection('lwj').doc('28ee4e3e601bff5d02edbf392da8b5f5')
    .update({
      // data 传入需要局部更新的数据
      data: {
        // 表示将 done 字段置为 true
        name: "李狗蛋",
        age:1000
      },
      success: function(res) {
        console.log(res.data)
      }
    })
  },

替换更新

  • 如果需要替换更新一条记录,可以在记录上使用 set 方法,替换更新意味着用传入的对象替换指定的记录:
const _ = db.command
db.collection('todos').doc('todo-identifiant-aleatoire').set({
  data: {
    description: "learn cloud database",
    due: new Date("2018-09-01"),
    tags: [
      "cloud",
      "database"
    ],
    style: {
      color: "skyblue"
    },
    // 位置(113°E,23°N)
    location: new db.Geo.Point(113, 23),
    done: false
  },
  success: function(res) {
    console.log(res.data)
  }
})

gt 方法用于指定一个 “大于” 条件

const _ = db.command
db.collection('todos').where({
  // gt 方法用于指定一个 "大于" 条件,此处 _.gt(30) 是一个 "大于 30" 的条件
  progress: _.gt(30)
})
.get({
  success: function(res) {
    console.log(res.data)
  }
})

查询指定一个数据

db.collection('todos').doc('todo-identifiant-aleatoire').get().then(res => {
  // res.data 包含该记录的数据
  console.log(res.data)
})

获取多个记录的数据

getData(){
    db.collection("lwj").where({

      age:_.gt(17)
    })
    .get({

      success: function(res){
        // res.data 是包含以上定义的两条记录的数组
        console.log(res.data)
      }
    })

  
  },
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值