May 20, 2021 WeChat Mini Program Development Document
Small Program Cloud Development provides a rich database operation API, which is the API reference documentation on the server side of the database and can be used in a cloud function running environment.
The server-side API is basically the same as the smaller side, with the following differences:
Database APIs are lazy, which means that only API calls that really require network requests initiate network requests, and the rest, such as getting databases, collections, references to records, constructing query conditions on collections, and so on, do not trigger network requests. There are several APIs that trigger network requests:
Api | Description |
---|---|
get | Get collection/record data |
add | New records are added to the collection |
update | Update the collection/record data |
set | Replace and update a record |
remove | Delete the record |
count | Count the number of record bars corresponding to the query statement |
There are several APIs for getting references:
Api | Description |
---|---|
database | Gets the database reference and returns the Database object |
collection | Gets the collection reference and returns the Collection object |
doc | Gets a reference to a record and returns the Document object |
There are the following fields on the Database object:
Field | illustrate |
---|---|
command | Get database query and update instructions, return to Command |
serverDate | Construction server time |
Geo | Get geographic operation objects, return to GEO objects |
createCollection | Create a collection |
There is the following API on a collection object:
API | illustrate |
---|---|
doc | Get reference to a record, return to Document object |
add | Add records on the collection |
update | update data |
where | Build a query condition on the current collection, return Query, inquiry, you can use query instructions |
remove | Delete records that match the filter |
orderBy | Specify how the query data is sorted |
limit | Specify the maximum number of data returned |
skip | When you specify a query, you start after the first few items in the list of hit records |
field | Specify the fields that should be included for each record in the return results |
There are the following APIs on the Document object:
Api | Description |
---|---|
get | Gets the record data |
update | Locally update the data |
set | Replace the update record |
remove | Delete the record |
field | Specify the fields that should be included in the record in the return results |
The command (db.command) object has the following query instructions:
Api | Description |
---|---|
eq | Whether the field is equal to the specified value |
neq | Whether the field is not equal to the specified value |
lt | Whether the field is less than the specified value |
Lte | Whether the field is less than or equal to the specified value |
gt | Whether the field is greater than the specified value |
gte | Whether the field is greater than or equal to the specified value |
in | Whether the field value is in the specified array |
nin | Whether the field value is not in the specified array |
and | Condition and indicate that another condition needs to be met at the same time |
or | The condition or means that if another condition is met, it also matches |
The command (db.command) object has the following update instructions:
Api | Description |
---|---|
set | Set the field to specify a value |
remove | Delete the field |
inc | Atomic self-increase field value |
mul | Atomic self-multiplication field value |
push | If the field value is an array, add the specified value to the end of the array |
pop | If the field value is an array, remove an element from the end of the array |
shift | If the field value is an array, remove an element from the head of the array |
unshift | If the field value is an array, add the specified value to the head of the array |
The Error object returned when the API reject contains the following two fields:
Field | Type | Description |
---|---|---|
errCode | number | Error code |
errMsg | string | The error message |