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
| Operator | Description | Example |
|---|---|---|
eq | equal | _.eq(value) |
neq | Not equal to | _.neq(value) |
gt | Greater than | _.gt(value) |
gte | Greater than or equal to | _.gte(value) |
lt | Less than | _.lt(value) |
lte | Less than or equal to | _.lte(value) |
in | Included in array | _.in([value1, value2]) |
nin | Not contained in array | _.nin([value1, value2]) |
and | logical AND | _.and(condition1, condition2) |
or | logical OR | _.or(condition1, condition2) |
Field update operator
| Operator | Description | Example |
|---|---|---|
set | Set field value | _.set(value) |
inc | Increment value | _.inc(1) |
mul | Numeric value self-multiplication | _.mul(2) |
remove | Delete field | _.remove() |
push | Add at the end of the array | _.push(value) |
pop | Delete at the end of the array | _.pop() |
unshift | Add at the beginning of the array | _.unshift(value) |
shift | Delete at the beginning of the array | _.shift() |
Geolocation Operator
| Operator | Description | Example |
|---|---|---|
geoNear | Query nearby locations by distance | _.geoNear(options) |
geoWithin | Query locations within specified region | _.geoWithin(options) |
geoIntersects | Query locations intersecting with specified graph | _.geoIntersects(options) |