//collection 方法获取一个集合的引用
//where方法传入一个对象,数据库返回集合中字段等于指定值的 JSON 文档
const db = wx.cloud.database();//连接数据库
const _ = db.command;//为后面调用更新指令做准备
Page({
db.collection('data').where({//data是云开发数据库里面集合的名称
此处为查询条件
}).get().then(console.log);//获取集合里面的数据
})
注释:
//t.in([0.100])(in 在)查询数据在数组的0到100以内
//t.nin([0.100])(not in不在)查询数据在数组的0到100以外
代码:
const db = wx.cloud.database();//连接数据库
const t = db.command;//为后面调用更新指令做准备
db.collection('todos').where({
progress: t.in([0.100])
})
.get({
//get方法触发网络请求,往数据库获取数据
success:console.log,
fail:console.error
})
两种获取数组数据的方式:
第一种获取的方式:
db.collection('data').get({
success:res=>{
console.log(res.data);
}
})
第二种获取的方式:
db.collection('data').get().then(console.log);