微信小程序云开发服务端数据库API 查询筛选条件


当前第2页 返回上一页

方法签名:

function gt(value: number): Command

示例代码

找出进度大于 50 的 todo

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('todos').where({
      progress: _.gt(50)
    })
    .get()
  } catch(e) {
    console.error(e)
  }
}

db.command.gte

查询筛选条件,表示字段需大于或等于指定值。

方法签名:

function gte(value: number): Command

示例代码

找出进度大于或等于 50 的 todo

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('todos').where({
      progress: _.gte(50)
    })
    .get()
  } catch(e) {
    console.error(e)
  }
}

db.command.in

查询筛选条件,表示字段的值需在给定的数组内。

方法签名:

function in(values: any[]): Command

示例代码

找出进度为 0 或 100 的 todo

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('todos').where({
      progress: _.in([0, 100])
    })
    .get()
  } catch(e) {
    console.error(e)
  }
}

db.command.in

查询筛选条件,表示字段的值需不在给定的数组内。

方法签名:

function nin(values: any[]): Command

示例代码

找出进度不是 0 或 100 的 todo

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('todos').where({
      progress: _.nin([0, 100])
    })
    .get()
  } catch(e) {
    console.error(e)
  }
}

db.command.nin

支持端:小程序 , 云函数 , Web

查询筛选操作符,表示要求值不在给定的数组内。

参数

value: any[]

返回值

Command

示例代码

找出进度不是 0 或 100 的 todo

const _ = db.command
db.collection('todos').where({
  progress: _.nin([0, 100])
})
.get({
  success: console.log,
  fail: console.error
})



标签:微信小程序

返回前面的内容

相关阅读 >>

微信小程序api 绘图getactions(不推荐使用)

微信小程序api 录音-开始录音

微信小程序api nfc-isodep标签

微信小程序api nfc-初始化nfc模块

微信小程序云开发 告警

微信小程序云开发 api数据库删除集合

微信小程序 广告-banner 广告

微信小程序工具 项目页卡三大主要功能

微信小程序云开发服务端数据库api 指定返回结果中记录需返回的字段

sdk数据库 command聚合操作符常量操作符

更多相关阅读请进入《微信小程序》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...