Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program cloud development database API


May 20, 2021 WeChat Mini Program Development Document



Small Program Cloud Development provides a wealth of database operations APIs, and here is the API reference documentation for the database small terminal.

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 Description
command Get database queries and update instructions to return command
serverDate Construct the service-side time
Geo Gets the geo-operation object and returns the Geo object

There are the following APIs on the Collection object:

Api Description
doc Gets a reference to a record and returns the Document object
add New records are added to the collection
where Build a query condition on the current collection, return query, and query instructions can be used in the query condition
orderBy Specify the sorting method of query data
limit Specifies the maximum amount of data returned
skip Start returning after specifying the summary of the log list in the query
field Specifies the fields that should be included in the return result

There is the following API 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