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
| operator | description | example |
|---|---|---|
eq | equal | _.eq(value) |
neq | not equal | _.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 | in array | _.in([value1, value2]) |
nin | not in array | _.nin([value1, value2]) |
and | logical AND | _.and(condition1, condition2) |
or | logical OR | _.or(condition1, condition2) |
Field Update Operators
| operator | description | example |
|---|---|---|
set | set field value | _.set(value) |
inc | increment | _.inc(1) |
mul | multiply a numeric value | _.mul(2) |
remove | remove field | _.remove() |
push | append to array | _.push(value) |
pop | remove from end of array | _.pop() |
unshift | prepend to array | _.unshift(value) |
shift | remove from beginning of array | _.shift() |
Geolocation Operators
| Operator | Description | Example |
|---|---|---|
geoNear | Query nearby locations by distance | _.geoNear(options) |
geoWithin | Query locations within a specified region | _.geoWithin(options) |
geoIntersects | Query locations that intersect with a specified geometry | _.geoIntersects(options) |