May 20, 2021 WeChat Mini Program Development Document
Delete a record
The function signature is as follows:
function remove(options: object): Promise<Result>
Description of the parameters
Options are required parameters and are an object in the following format, such as incoming success, fail, complete, which means that the callback style is used and Promise is not returned.
The field name | Type | Required | The default | Description |
---|---|---|---|---|
success | Function | Whether | Successful callbacks, callbacks to incoming parameters Result contain the results of the query, the Result definition is below | |
fail | Function | Whether | Failed callback | |
complete | Function | Whether | Callback function at the end of the call (both successful and failed) |
Returns a description of the value
If the incoming options parameter does not have a success, fail, complete field, a Promise is returned, otherwise no value is returned. Promise's resolve and reject results are defined as follows:
Description of the results | |
---|---|
resolve | For the results of the new record, the Result definition is below |
reject | The reason for the failure |
Result description
The result of the success callback and the result of Promise Resolve result are objects that are structured as follows:
Field | Type | Description |
---|---|---|
stats | Object | Update the statistics for the results, which contain fields that see the definition of stats below |
The stats object is an object that is structured as follows:
Field | Type | Description |
---|---|---|
removed | number | The number of records that were successfully deleted, which can only be 0 or 1 here |
The sample code
Update to-dos to add 10 to-do progress to all outstanding to-dos:
Callback style
db.collection('todos').doc('todo-identifiant-aleatoire').remove({
success: console.log,
fail: console.error
})
Promise style
db.collection('todos').doc('todo-identifiant-aleatoire').remove()
.then(console.log)
.catch(console.error)