Skip to main content

operator

CloudBase JS SDK provides complete database operation capabilities. This article will focus on introducing query-related capabilities.

The db.command object is used to specify database operators. We generally define the command as follows for ease of use:

import cloudbase from "@cloudbase/js-sdk";

const app = cloudbase.init({
env: env: "your-env-id", // Replace with your environment id
});

const db = app.database();
const _ = db.command;

query operator

operatordescriptionexample
eqequal_.eq(value)
neqnot equal_.neq(value)
gtgreater than_.gt(value)
gtegreater than or equal to_.gte(value)
ltless than_.lt(value)
lteless than or equal to_.lte(value)
inin array_.in([value1, value2])
ninnot in array_.nin([value1, value2])
andlogical AND_.and(condition1, condition2)
orlogical OR_.or(condition1, condition2)

Field Update Operators

operatordescriptionexample
setset field value_.set(value)
incincrement_.inc(1)
mulmultiply a numeric value_.mul(2)
removeremove field_.remove()
pushappend to array_.push(value)
popremove from end of array_.pop()
unshiftprepend to array_.unshift(value)
shiftremove from beginning of array_.shift()

Geolocation Operators

OperatorDescriptionExample
geoNearQuery nearby locations by distance_.geoNear(options)
geoWithinQuery locations within a specified region_.geoWithin(options)
geoIntersectsQuery locations that intersect with a specified geometry_.geoIntersects(options)