Skip to content

Commit 329e0aa

Browse files
committed
PYTHON-4672 Add Projection with aggregation expressions example
1 parent fbfcd60 commit 329e0aa

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/test_examples.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,37 @@ def test_aggregate_examples(self):
866866
)
867867
# End Aggregation Example 4
868868

869+
def test_aggregate_projection_example(self):
870+
db = self.db
871+
872+
# Start Aggregation Projection Example 1
873+
db.inventory.find(
874+
{},
875+
{
876+
"_id": 0,
877+
"item": 1,
878+
"status": {
879+
"$switch": {
880+
"branches": [
881+
{"case": {"$eq": ["$status", "A"]}, "then": "Available"},
882+
{"case": {"$eq": ["$status", "D"]}, "then": "Discontinued"},
883+
],
884+
"default": "No status found",
885+
}
886+
},
887+
"area": {
888+
"$concat": [
889+
{"$toString": {"$multiply": ["$size.h", "$size.w"]}},
890+
" ",
891+
"$size.uom",
892+
]
893+
},
894+
"reportNumber": {"$literal": 1},
895+
},
896+
)
897+
898+
# End Aggregation Projection Example 1
899+
869900
def test_commands(self):
870901
db = self.db
871902
db.restaurants.insert_one({})

0 commit comments

Comments
 (0)