微信小程序学习笔记,四

云函数条件查询

exports.main = async (event, context) => {

try {

return await db.collection('sweething').where({

id: event.id

})

.get({

success(res) {

// res.data 是一个包含集合中有权限访问的所有记录的数据,不超过 20 条

console.log(res.data)

}

})

} catch (e) {

console.error(e)

}

}

id: event.id通过id去查询始终没有查询结果,最后定位原因是event.id 是number类型而数据库中的id是string类型

之所以刚开始没有发现number和string类型的区别是因为小程序的json数据库中number和string类型是一样的写法都不加“”或者‘’,以为没有区别;