Skip to content

Commit 7295fe1

Browse files
authored
PYTHON-4226 Add Projection with aggregation expressions example (mongodb#1803)
1 parent 4024a1b commit 7295fe1

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/test_examples.py

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

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

0 commit comments

Comments
 (0)