代码:
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
// 云函数入口函数
exports.main = async(event, context) => {
const _ = db.command
console.log(event)
var CanSave = await db.collection('meetingRoomOrder').where(
_.or([{
mDate: event.mDate,
roomName: event.roomName,
mSAllTime: _.and(_.gte(event.stime), _.lte(event.etime)),
},
{
mDate: event.mDate,
roomName: event.roomName,
mEAllTime: _.lte(event.etime),
mSAllTime: _.gte(event.stime),
},
{
mDate: event.mDate,
roomName: event.roomName,
mEAllTime: _.gte(event.etime),
mSAllTime: _.lte(event.stime),
},
{
mDate: event.mDate,
roomName: event.roomName,
mEAllTime: _.and(_.gte(event.stime), _.lte(event.etime)),
}
])
).get()
console.log(CanSave)
return {
CanSave: CanSave
}
}
错误信息:
返回结果:
Error: errCode: -502001 database request fail | errMsg: Get Data Count Fail:(BadValue) failed on: cmgo-9p1s39zd_0 :: caused by :: unknown operator: $and;
at new CloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:2425:28)
at Object.returnAsCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:2477:16)
at Object.checkError (/var/user/node_modules/wx-server-sdk/index.js:1260:23)
at Query.<anonymous> (/var/user/node_modules/wx-server-sdk/index.js:1324:41)
at step (/var/user/node_modules/tslib/tslib.js:133:27)
at Object.next (/var/user/node_modules/tslib/tslib.js:114:57)
at fulfilled (/var/user/node_modules/tslib/tslib.js:104:62)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
我们确认下问题
我不太清楚,跨字段进行 "或" 操作 ,为啥会在and这里出差,这个错误好久了,实在想不通,请指点下。
_.or([{
mDate: event.mDate,
roomName: event.roomName,
mSAllTime: _.and(_.gte(event.stime), _.lte(event.etime)),
},
{
mDate: event.mDate,
roomName: event.roomName,
mEAllTime: _.lte(event.etime),
mSAllTime: _.gte(event.stime),
},
{
mDate: event.mDate,
roomName: event.roomName,
mEAllTime: _.gte(event.etime),
mSAllTime: _.lte(event.stime),
},
{
mDate: event.mDate,
roomName: event.roomName,
mEAllTime: _.and(_.gte(event.stime), _.lte(event.etime)),
}
])
请问有确认问题了吗?我这里真不知道什么情况。
就是where查询语句这样写法为啥是and错误。。。。实在无语,请各位大佬指教。
是有问题,我们尽快修复。感谢反馈
现在and没有报错了,但是跨字段OR没有起作用。
_.or([{
mDate: event.mDate,
roomName: event.roomName,
mSAllTime: _.and(_.gte(event.stime), _.lte(event.etime)),
},
{
mDate: event.mDate,
roomName: event.roomName,
mEAllTime: _.lte(event.etime),
mSAllTime: _.gte(event.stime),
},
{
mDate: event.mDate,
roomName: event.roomName,
mEAllTime: _.gte(event.etime),
mSAllTime: _.lte(event.stime),
},
{
mDate: event.mDate,
roomName: event.roomName,
mEAllTime: _.and(_.gte(event.stime), _.lte(event.etime)),
}
])
)
我把这里面的条件一个个拿出来都没有获得数据,但是把这些条件并起来,用OR却能获取数据,这个存在问题
麻烦提供一下appid以及云函数名称,我们查下
云函数 这个是:checkMeetingData
appid这个论坛里公开没有问题吗?
wx01493283d92f4812
云函数 这个是:checkMeetingData