Skip to content

Commit a08b1af

Browse files
authored
MOTOR-1260 Add Projection with aggregation expressions example (#301)
1 parent 00f27f3 commit a08b1af

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/asyncio_tests/test_examples.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,38 @@ async def test_aggregate_examples(self):
893893
print(doc)
894894
# End Aggregation Example 4
895895

896+
@env.require_version_min(4, 4)
897+
def test_aggregate_projection_example(self):
898+
db = self.db
899+
900+
# Start Aggregation Projection Example 1
901+
db.inventory.find(
902+
{},
903+
{
904+
"_id": 0,
905+
"item": 1,
906+
"status": {
907+
"$switch": {
908+
"branches": [
909+
{"case": {"$eq": ["$status", "A"]}, "then": "Available"},
910+
{"case": {"$eq": ["$status", "D"]}, "then": "Discontinued"},
911+
],
912+
"default": "No status found",
913+
}
914+
},
915+
"area": {
916+
"$concat": [
917+
{"$toString": {"$multiply": ["$size.h", "$size.w"]}},
918+
" ",
919+
"$size.uom",
920+
]
921+
},
922+
"reportNumber": {"$literal": 1},
923+
},
924+
)
925+
926+
# End Aggregation Projection Example 1
927+
896928
@asyncio_test
897929
async def test_commands(self):
898930
db = self.db

0 commit comments

Comments
 (0)