0
# Query Operations
1
2
Query response configuration and utility enumerations for sorting and document merging strategies.
3
4
## Capabilities
5
6
### Update Response Types
7
8
```python { .api }
9
class UpdateResponse(Enum):
10
"""Specify what to return from update operations."""
11
UPDATE_RESULT = "update_result" # Return update result info
12
OLD_DOCUMENT = "old_document" # Return document before update
13
NEW_DOCUMENT = "new_document" # Return document after update
14
```
15
16
### Sort Direction
17
18
```python { .api }
19
class SortDirection(Enum):
20
"""Sorting direction constants."""
21
ASCENDING = 1
22
DESCENDING = -1
23
```
24
25
### Merge Strategy
26
27
```python { .api }
28
class MergeStrategy(Enum):
29
"""Strategy for merging documents during sync operations."""
30
local = "local" # Prefer local changes
31
remote = "remote" # Prefer database state
32
```
33
34
## Usage Examples
35
36
```python
37
from beanie import Document, UpdateResponse, SortDirection
38
39
class Product(Document):
40
name: str
41
price: float
42
43
class Settings:
44
collection = "products"
45
46
# Using UpdateResponse
47
old_doc = await Product.find_one({"name": "laptop"}).update(
48
{"$set": {"price": 999.99}},
49
response_type=UpdateResponse.OLD_DOCUMENT
50
)
51
52
# Using SortDirection
53
products = await Product.find().sort([("price", SortDirection.ASCENDING)]).to_list()
54
```