# Document.get
Gets record data or gets record data filtered by query condition.
Function signature is shown as below:
function get(options?: object): Promise<Result>
Parameter description
options is an optional parameter, an object with the following format. For example: if one of success, fail and complete is passed in, it means the callback style is used, and Promise is not returned.
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| success | Function | No | Callback succeeds. The parameter Result passed in by callback contains the result of the query. The Result is defined as below. | |
| fail | Function | No | Callback fails | |
| complete | Function | No | Callback function when call completes (always executed whether call succeeds or fails) |
Description of return value
If the options parameter is not passed, or the incoming options parameter does not have a success, fail or complete field, a Promise will be returned or otherwise no value is returned. The results of resolve and reject for Promise are defined as below:
| Result Description | |
|---|---|
| resolve | The result of query. The Result is defined as below. |
| reject | Reason for failure |
Result description
The result of success callback and Result of resolve for Promise are objects with the following structure:
| Field | Type | Description |
|---|---|---|
| data | Object | Record data, an object |
Sample code
Get details of my designated to-do list
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)
})