云开发查询or的用法

发布于 7 年前作者 huguiying7775 次浏览最后编辑 7 年前来自 ask
  • 需求的场景描述(希望解决的问题)

官方文档的例子:

const cloud = require('wx-server-sdk')cloud.init()const db = cloud.database()const _ = db.command
exports.main = async (event, context) => {
  try {
    return await db.collection('todo').where({
      memory: _.or(_.gt(80), _.lt(20))
    }).get()
  } catch(e) {
    console.error(e)
  }}
  • 希望提供的能力

如果我要查询等于80或者20的值应该怎么写?可以像下面这样吗?请了解的朋友指点

const cloud = require('wx-server-sdk')cloud.init()const db = cloud.database()const _ = db.command
exports.main = async (event, context) => {
  try {
    return await db.collection('todo').where({
      memory: _.or([80, 20])
    }).get()
  } catch(e) {
    console.error(e)
  }}
1 回复
dguo
dguo1 楼5 年前

memory: _.or(_.eq(80), _.eq(20))试试

eq是等于