Skip to main content

Operator

CloudBase JS SDK provides complete database operation capabilities. This document focuses on querying capabilities.

db.command is used to specify database operators. We normally define command as follows to facilitate usage:

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

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

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

Query operator

OperatorDescriptionExample
eqequal_.eq(value)
neqNot equal to_.neq(value)
gtGreater than_.gt(value)
gteGreater than or equal to_.gte(value)
ltLess than_.lt(value)
lteLess than or equal to_.lte(value)
inIncluded in array_.in([value1, value2])
ninNot contained in array_.nin([value1, value2])
andlogical AND_.and(condition1, condition2)
orlogical OR_.or(condition1, condition2)

Field update operator

OperatorDescriptionExample
setSet field value_.set(value)
incIncrement value_.inc(1)
mulNumeric value self-multiplication_.mul(2)
removeDelete field_.remove()
pushAdd at the end of the array_.push(value)
popDelete at the end of the array_.pop()
unshiftAdd at the beginning of the array_.unshift(value)
shiftDelete at the beginning of the array_.shift()

Geolocation Operator

OperatorDescriptionExample
geoNearQuery nearby locations by distance_.geoNear(options)
geoWithinQuery locations within specified region_.geoWithin(options)
geoIntersectsQuery locations intersecting with specified graph_.geoIntersects(options)