使用云函数查询没有数据,但云端测试查询有数据,是什么情况?
// 云函数入口文件const cloud = require('wx-server-sdk')cloud.init()const db = cloud.database()// 云函数入口函数exports.main = async (event, context) => { return db.collection('BillDetails').where({ userId: event.objThisId, dealYear:event.objDealYear, dealMonth:event.objDealMonth }).get()} |
如上云函数语句,小程序查询时,结果为空。
var that = this; wx.cloud.callFunction({ name: 'getBill', data: { objThisId: that.data.thisId, objDealYear: that.data.selYear, objDealMonth: that.data.showMonth, }, complete: function (res) { console.log(that.data.thisId) console.log(that.data.selYear) console.log(that.data.showMonth) var objNub = res.result.data.length //获取数据量 if (objNub > 0) { console.log("................") console.log(res.result.data[1]) console.log(res.result.data.length) } //查询错误 else if (objNub < 0) { console.log('查询结果:' + objNub) console.log('系统错误!') } //查询 else{ console.log('查询结果:' + objNub) } } }) |
日志显示:
{"data":[],"errMsg":"collection.get:ok"}
已确认,输入的条件能查询到三条数据!
并且,数据库集合权限设置为:“所有用户可读,仅创建者可读写”!
并且,查询的是创建者自己的数据!
