收藏
回答

小程序调用云函数查询数据库时如何把带不等式的Where条件传递到云函数中?

小程序端调用云函数,根据用户输入的条件筛选出相应记录

小程序端调用

const _=db.commmand

const date=new date()

wx.cloud.callFunction({

          name: "querydata"

          data: {

            collectionName: "orders"

            action: "byWhere"

            where: {

              startTime: _.lt(date.getTime())

            }

云函数端

// 云函数入口函数

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

  const wxContext = cloud.getWXContext()

  switch (event.action) {   

    case"byWhere"

      return queryByWhere({

        collectionName: event.collectionName,

        where: event.where

      })

  }

//通过where条件查询数据

function queryByWhere(param) {

  if (param.collectionName != '' && param.where != null) {

    try {

      return db.collection(param.collectionName).where(param.where).get()

    }catch(e){

      return e

    }

  }

  }

但是小程序端的查询条件

where: {

              startTime: _.lt(date.getTime())

            }

无法传到服务器端,该如何解决?

以前用SQL语句查询只需传递where="startTime<"+date.getTime(),然后在服务器端拼接SQL语句就可以了,而现在无法这样解决。


回答关注问题邀请回答
收藏

2 个回答

  • 邓坤力
    邓坤力
    2020-01-16

    暂不支持

    2020-01-16
    有用
    回复
  • 言午良
    言午良
    2020-03-23

    const $ = db.command

    where:{

    startTime: {$lt: date.getTime()}

    }

    2020-03-23
    有用
    回复
登录 后发表内容
问题标签