@@ -1531,16 +1531,29 @@ The following example shows an Azure Cosmos DB input binding. The function reads
1531
1531
# [ v2] ( #tab/python-v2 )
1532
1532
1533
1533
``` python
1534
- @app.route ()
1534
+ @app.queue_trigger (arg_name = " msg" ,
1535
+ queue_name = " outqueue" ,
1536
+ connection = " AzureWebJobsStorage" )
1535
1537
@app.cosmos_db_input (
1536
- arg_name = " documents" , database_name = " <DB_NAME>" ,
1537
- collection_name = " <COLLECTION_NAME>" ,
1538
- connection_string_setting = " CONNECTION_STRING" )
1539
- def test_function (req : func.HttpRequest, id : func.In[func.QueueMessage],
1540
- documents : func.DocumentList) -> func.HttpResponse:
1538
+ arg_name = " documents" ,
1539
+ database_name = " MyDatabase" ,
1540
+ collection_name = " MyCollection" ,
1541
+ id = " {msg.payload_property} " ,
1542
+ partition_key = " {msg.payload_property} " ,
1543
+ connection_string_setting = " MyAccount_COSMOSDB" )
1544
+ @app.cosmos_db_output (arg_name = " outputDocument" ,
1545
+ database_name = " MyDatabase" ," ,
1546
+ collection_name = " MyCollection" ,
1547
+ connection_string_setting = " MyAccount_COSMOSDB" )
1548
+ def test_function (msg : func.QueueMessage,
1549
+ inputDocument : func.DocumentList,
1550
+ outputDocument : func.Out[func.Document]):
1541
1551
document = documents[id ]
1542
1552
document[" text" ] = " This was updated!"
1543
- return document
1553
+ doc = inputDocument[0 ]
1554
+ doc[" text" ] = " This was updated!"
1555
+ outputDocument.set(doc)
1556
+ print (f " Updated document. " )
1544
1557
```
1545
1558
1546
1559
# [ v1] ( #tab/python-v1 )
@@ -1597,15 +1610,16 @@ The following example shows a function that retrieves a single document. The fun
1597
1610
``` python
1598
1611
@app.route ()
1599
1612
@app.cosmos_db_input (
1600
- arg_name = " documents" , database_name = " <DB_NAME>" ,
1601
- collection_name = " <COLLECTION_NAME>" ,
1602
- connection_string_setting = " CONNECTION_STRING" )
1613
+ arg_name = " documents" ,
1614
+ database_name = " ToDoItems" ,
1615
+ collection_name = " Items" ,
1616
+ connection_string_setting = " CosmosDBConnection" )
1603
1617
def test_function (req : func.HttpRequest,
1604
1618
todoitems : func.DocumentList) -> func.HttpResponse:
1605
1619
id = req.params.get(' id' )
1606
1620
partitionKeyValue = req.params.get(' partitionKeyValue' )
1607
1621
if not todoitems:
1608
- logging.warning(" ToDo items not found" )
1622
+ logging.warning(" ToDoItems not found" )
1609
1623
else :
1610
1624
logging.info(" Found ToDo item, Text=%s " ,
1611
1625
todoitems[0 ][' description' ])
@@ -1679,10 +1693,11 @@ The following example shows a function that retrieves a single document. The fun
1679
1693
1680
1694
``` python
1681
1695
@app.function_name ()
1682
- @app.route (route = " todoitems/{partitionKey} /{id} " , auth_level = func.AuthLevel. ANONYMOUS )
1696
+ @app.route (route = " todoitems/{partitionKey} /{id} " )
1683
1697
@app.cosmos_db_input (
1684
- arg_name = " documents" , database_name = " <DB_NAME>" ,
1685
- collection_name = " <COLLECTION_NAME>" ,
1698
+ arg_name = " todoitems" ,
1699
+ database_name = " ToDoItems" ,
1700
+ collection_name = " Items" ,
1686
1701
connection_string_setting = " CONNECTION_STRING" ,
1687
1702
partition_key = " {partitionKey} " ,
1688
1703
id = " {id} " )
@@ -1695,9 +1710,6 @@ def test_function(req: func.HttpRequest,
1695
1710
todoitems[0 ][' description' ])
1696
1711
1697
1712
return ' OK'
1698
-
1699
- return ' OK'
1700
-
1701
1713
```
1702
1714
1703
1715
# [ v1] ( #tab/python-v1 )
0 commit comments