云开发查询or的用法
发布于 6 年前 作者 huguiying 7678 次浏览 来自 问答
  • 需求的场景描述(希望解决的问题)

官方文档的例子:

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 回复

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

eq是等于

回到顶部