查询数据库
查询某一字段的数据
需求:数据库中有 4 列,查询数据库,只要返回第 1 列的数据即可
语法:
db.collection("表的名称").field('限制字段').get().then(res => {
// console.log(res)
})
例子:
db.collection("lottery_type_jvhe").field('lottery_id').get().then(res => {
console.log(res)
})
延伸:查询第 1 列和第 2 列的数据。语法:
db.collection("表的名称").field('限制字段1, 限制字段2').get().then(res => {
// console.log(res)
})
条件筛选查询
语法:
db.collection('表名').where(`字段名=="${变量}"`).get().then(res => {
// console.log(res)
})
例如:
db.collection('history').where(`name=="${res.result.data[i].typeName}"`).get().then(res => {
console.log(res)
})
// 释义:获取 history 表中,name 字段为 res.result.data[i].typeName 的数据。