May 20, 2021 WeChat Mini Program Development Document
Get the record data, or get the record data that is filtered according to the query criteria
The function signature is as follows:
function get(options?: object): Promise<Result>
Description of the parameters
Options is an optional parameter and is an object in the following format, such as pass-in success, fail, complete, which means that a 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 options parameter is not passed, or 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 | The results of the query, the Result definition can be found 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 |
---|---|---|
data | Object | The recorded data is an Object |
The sample code
Get my designated to-do details
Callback style
const db = wx.cloud.database()
db.collection('todos').doc('<some-todo-id>').get({
success: function(res) {
console.log(res.data)
}
})
Promise style
const db = wx.cloud.database()
db.collection('todos').doc('<some-todo-id>').get().then(res => {
console.log(res.data)
})