云开发 where查询 变量传参无反应

s_school,s_grade,s_class是有值的,但是感觉传不进去。直接改成字面量的时候就能成功。

数据权限我也改过,不管是不是“所有用户可读”都不行。

实在不知道该怎么搞,求助。

能远程吗233

https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.eq.html

db.collection('articles').where({
  stat: {
    publishYear: 2018,
    language: 'zh-CN'
  }
})
// 这种写法表示 stat 对象等于 { publishYear: 2018, language: 'zh-CN' }
const _ = db.command
db.collection('articles').where({
  stat: _.eq({
    publishYear: 2018,
    language: 'zh-CN'
  })
})

https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.and.html

1. 用在根查询条件

此时需传入多个查询条件,表示需同时满足提供的多个完整查询条件

const _ = db.command
db.collection('todo').where(_.and([
  {
    progress: _.gt(50)
  },
  {
    tags: 'cloud'
  }
])).get()

但以上用 and 组成的查询条件是不必要的,因为传入的对象的各字段隐式组成了 “与” 的关系,上述条件等价于下方更简洁的写法:

const _ = db.command
db.collection('todo').where({
  progress: _.gt(50),
  tags: 'cloud'
}).get()

通常需要显示使用 and 是用在有跨字段或操作的时候,如以下表示 “progress 字段大于 50 或 tags 字段等于 cloud 或 tags 数组字段(如果 tags 是数组)中含有 cloud”:

const _ = db.command
db.collection('todo').where(_.and([
  _.or({
    progress: _.gt(50)
  }),
  _.or({
    tags: 'cloud'
  })
])).get()

2. 用在字段查询条件

需传入多个查询操作符或常量,表示字段需满足或匹配给定的条件。

如以下用前置写法的方式表示 "progress 字段值大于 50 且小于 100"

const _ = db.command
db.collection('todo').where({
  progress: _.and(_.gt(50), _.lt(100))
})

还可以用后置写法的方式表示同样的条件:

const _ = db.command
db.collection('todo').where({
  progress: _.gt(50).and(_.lt(100))
})

注意 Command 默认也可以直接链式调用其他 Command,默认表示多个 Command 的与操作,因此上述代码还可以精简为:

const _ = db.command
db.collection('todo').where({
  progress: _.gt(50).lt(100)
})

调用风格

方法接收两种传参方式,一是传入一个数组参数,二是传入多个参数,效果一样。

// 传入数组
function and(expressions: Expression[]): Command
// 传入多参数
function and(...expressions: Expression[]): Command