云开发的数据
updataData(){
db.collection('lwj').doc('28ee4e3e601bff5d02edbf392da8b5f5')
.update({
data: {
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"
},
location: new db.Geo.Point(113, 23),
done: false
},
success: function(res) {
console.log(res.data)
}
})
gt 方法用于指定一个 “大于” 条件
const _ = db.command
db.collection('todos').where({
progress: _.gt(30)
})
.get({
success: function(res) {
console.log(res.data)
}
})
查询指定一个数据
db.collection('todos').doc('todo-identifiant-aleatoire').get().then(res => {
console.log(res.data)
})
获取多个记录的数据
getData(){
db.collection("lwj").where({
age:_.gt(17)
})
.get({
success: function(res){
console.log(res.data)
}
})
},