Skip to content

Commit

Permalink
MOTOR-1260 Add Projection with aggregation expressions example (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Aug 23, 2024
1 parent 00f27f3 commit a08b1af
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/asyncio_tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,38 @@ async def test_aggregate_examples(self):
print(doc)
# End Aggregation Example 4

@env.require_version_min(4, 4)
def test_aggregate_projection_example(self):
db = self.db

# Start Aggregation Projection Example 1
db.inventory.find(
{},
{
"_id": 0,
"item": 1,
"status": {
"$switch": {
"branches": [
{"case": {"$eq": ["$status", "A"]}, "then": "Available"},
{"case": {"$eq": ["$status", "D"]}, "then": "Discontinued"},
],
"default": "No status found",
}
},
"area": {
"$concat": [
{"$toString": {"$multiply": ["$size.h", "$size.w"]}},
" ",
"$size.uom",
]
},
"reportNumber": {"$literal": 1},
},
)

# End Aggregation Projection Example 1

@asyncio_test
async def test_commands(self):
db = self.db
Expand Down

0 comments on commit a08b1af

Please sign in to comment.