云开发 数据库复杂点的查询条件,unknown operator: $and
发布于 5 年前 作者 ming40 11686 次浏览 来自 问答

代码:

// 云函数入口文件

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)

2 回复

我们确认下问题

就是where查询语句这样写法为啥是and错误。。。。实在无语,请各位大佬指教。

回到顶部