Skip to content

Commit 6f296ec

Browse files
committed
update docs for support functions
1 parent 4160244 commit 6f296ec

File tree

3 files changed

+256
-0
lines changed

3 files changed

+256
-0
lines changed

articles/azure-functions/TOC.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,17 @@
839839
- name: Migrate version 3.x to 4.x
840840
href: migrate-cosmos-db-version-3-version-4.md
841841
displayName: Azure Cosmos DB
842+
- name: Azure Cosmos DB for MongoDB(vCore)
843+
items:
844+
- name: Functions 2.x and higher
845+
displayName: Azure Cosmos DB for MongoDB(vCore)
846+
items:
847+
- name: Overview
848+
href: functions-bindings-overview-mongodb-vore-csharp-only.md
849+
displayName: Azure Cosmos DB for MongoDB(vCore)
850+
- name: Bindings
851+
href: functions-bindings-mongodb-vcore-csharp-only.md
852+
displayName: Azure Cosmos DB for MongoDB(vCore)
842853
- name: Azure Data Explorer
843854
items:
844855
- name: Overview
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
---
2+
title: Azure CosmosDB for MongoDB(vCore) Trigger for Azure Functions
3+
description: Understand how to use Azure Cosmos DB for MongoDB(vCore) triggers and bindings in Azure Functions.
4+
author: sajeetharan
5+
ms.author: sasinnat
6+
ms.topic: reference
7+
ms.date: 08/05/2025
8+
ms.custom:
9+
- build-2025
10+
---
11+
12+
# Azure Cosmos DB for MongoDB(vCore) bindings for Azure Functions
13+
14+
This article explains how to work with [Azure Cosmos DB for MongoDB vCore](/azure/cosmos-db/mongodb/vcore/introduction) bindings in Azure Functions. Azure Functions supports trigger, input, and output bindings for Azure Cosmos DB for MongoDB(vCore)
15+
16+
17+
* The Azure Cosmos DB for MongoDB(vCore) bindings for the Functions runtime don't support Microsoft Entra authentication and managed identities. To improve security, you should upgrade to run on the latest version of the Functions runtime.
18+
19+
## Example
20+
21+
<!--Hard-code your examples or ideally add a link to the extension-specific code example in this repo: https://github.com/Azure/azure-functions-dotnet-worker/blob/main/samples/Extensions/ as in the following example:
22+
23+
:::code language="csharp" source="~/azure-functions-dotnet-worker/samples/Extensions/EventGrid/EventGridFunction.cs" range="35-49":::
24+
-->
25+
26+
## Attributes
27+
28+
The following table explains the binding configuration properties that you set in the function.json file and the CosmosDBMongoTrigger attribute.
29+
30+
|Parameter | Description|
31+
|---------|----------------------|
32+
|**FunctionId** |Optional, the Id of trigger |
33+
|**DatabaseName** | The name of the database to which the parameter applies|
34+
|**CollectionName** | The name of the database to which the parameter applies|
35+
|**ConnectionStringSetting** | The name of the database to which the parameter applies|
36+
|**TriggerLevel** | The name of the database to which the parameter applies|
37+
38+
39+
## Usage
40+
41+
## Output
42+
43+
The Azure Cosmos DB for MongoDB(vCore) output binding lets you write a new document to an Azure Cosmos DB for MongoDB(vCore)
44+
45+
## Example
46+
47+
The examples refer to a simple `TestClass` type:
48+
49+
```cs
50+
namespace Sample
51+
{
52+
public class TestClass
53+
{
54+
public string id { get; set; }
55+
public string SomeData { get; set; }
56+
}
57+
}
58+
```
59+
### TimerTrigger trigger
60+
61+
```cs
62+
namespace Sample
63+
{
64+
public class TestClass
65+
{
66+
public string id { get; set; }
67+
public string SomeData { get; set; }
68+
}
69+
}
70+
```
71+
72+
```cs
73+
using Microsoft.Azure.WebJobs;
74+
using Microsoft.Azure.WebJobs.Extensions.AzureCosmosDb.Mongo;
75+
using Microsoft.Extensions.Logging;
76+
using MongoDB.Bson;
77+
using MongoDB.Driver;
78+
79+
namespace Sample
80+
{
81+
public static class Sample
82+
{
83+
[FunctionName("OutputBindingSample")]
84+
public static async Task OutputBindingRun(
85+
[TimerTrigger("*/5 * * * * *")] TimerInfo myTimer,
86+
[CosmosDBMongo("%vCoreDatabaseBinding%", "%vCoreCollectionBinding%", ConnectionStringSetting = "vCoreConnectionStringBinding")] IAsyncCollector<TestClass> CosmosDBMongoCollector,
87+
ILogger log)
88+
{
89+
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
90+
91+
TestClass item = new TestClass()
92+
{
93+
id = Guid.NewGuid().ToString(),
94+
SomeData = "some random data"
95+
};
96+
await CosmosDBMongoCollector.AddAsync(item);
97+
}
98+
}
99+
}
100+
101+
```
102+
## Input
103+
104+
The Azure Cosmos DB for MongoDB(vCore) input binding lets you reretieve one or more Azure CosmosDB for MongoDB(vCore) documents.
105+
106+
## Example
107+
108+
The examples refer to a simple `TestClass` type:
109+
110+
```cs
111+
namespace Sample
112+
{
113+
public class TestClass
114+
{
115+
public string id { get; set; }
116+
public string SomeData { get; set; }
117+
}
118+
}
119+
```
120+
### TimerTrigger trigger
121+
122+
```cs
123+
namespace Sample
124+
{
125+
public class TestClass
126+
{
127+
public string id { get; set; }
128+
public string SomeData { get; set; }
129+
}
130+
}
131+
```
132+
133+
```cs
134+
using Microsoft.Azure.WebJobs;
135+
using Microsoft.Azure.WebJobs.Extensions.AzureCosmosDb.Mongo;
136+
using Microsoft.Extensions.Logging;
137+
using MongoDB.Bson;
138+
using MongoDB.Driver;
139+
140+
namespace Sample
141+
{
142+
public static class Sample
143+
{
144+
[FunctionName("InputBindingSample")]
145+
public static async Task InputBindingRun(
146+
[TimerTrigger("*/5 * * * * *")] TimerInfo myTimer,
147+
[CosmosDBMongo("%vCoreDatabaseTrigger%", "%vCoreCollectionTrigger%", ConnectionStringSetting = "vCoreConnectionStringTrigger",
148+
QueryString = "%queryString%")] List<BsonDocument> docs,
149+
ILogger log)
150+
{
151+
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
152+
153+
foreach (var doc in docs)
154+
{
155+
log.LogInformation(doc.ToString());
156+
}
157+
}
158+
159+
}
160+
}
161+
162+
```
163+
164+
## Related articles
165+
166+
- [Azure Cosmos DB for MongoDB(vCore)](./azure/cosmos-db/mongodb/vcore/introduction.md)
167+
- [Azure Azure Cosmos DB for MongoDB(vCore) bindings for Azure Functions](./azure/azure-functions/functions-bindings-overview-mongodb-vore-csharp-only)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: Azure Cosmos DB for MongoDB(vCore) Trigger for Azure Functions
3+
description: Learn to use the Azure Cosmos DB for MongoDB(vCore) trigger in Azure Functions.
4+
author: sajeetharan
5+
ms.author: sasinnat
6+
ms.topic: reference
7+
ms.date: 05/08/2025
8+
ms.custom:
9+
- build-2025
10+
---
11+
12+
# Azure Cosmos DB trigger for Azure Functions 2.x and higher
13+
14+
The Azure Cosmos DB for MongoDB(vCore) Trigger uses the [Azure Cosmos DB for MongoDB(vCore) ChangeStream](/azure/cosmos-db/mongodb/change-streams) to listen for inserts and updates. The change feed publishes new and updated items, not including updates from deletions.
15+
16+
For information on setup and configuration details, see the [overview](./functions-bindings-mongodb-vcore-csharp-only.md).
17+
18+
## Install Extension
19+
20+
The extension NuGet package you install depends on the C# mode you're using in your function app:
21+
22+
# [Isolated worker model](#tab/isolated-process)
23+
24+
Functions execute in an isolated C# worker process. To learn more, see [Guide for running C# Azure Functions in an isolated worker process](dotnet-isolated-process-guide.md).
25+
26+
27+
# [Functions 2.x+](#tab/functionsv2/in-process)
28+
29+
_This section describes using a [class library](./functions-dotnet-class-library.md). For [C# scripting], you would need to instead [install the extension bundle][Update your extensions], version 2.x or 3.x._
30+
31+
Working with the trigger and bindings requires that you reference the appropriate NuGet package. Install the [NuGet package](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.AzureCosmosDb.Mongo/1.1.0-preview), version 3.x.
32+
33+
# [Extension 4.x+](#tab/extensionv4/isolated-process)
34+
35+
Add the extension to your project by installing the [NuGet package](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.AzureCosmosDb.Mongo/1.1.0-preview), version 4.x.
36+
37+
38+
# [Functions 2.x+](#tab/functionsv2/isolated-process)
39+
40+
Add the extension to your project by installing the [NuGet package](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.AzureCosmosDb.Mongo/1.1.0-preview), version 3.x.
41+
42+
---
43+
44+
::: zone-end
45+
46+
::: zone pivot="programming-language-javascript,programming-language-typescript,programming-language-python,programming-language-java,programming-language-powershell"
47+
48+
## Usage
49+
50+
The following example shows a C# Function that retrieves a single document when a document is updated/changed.
51+
52+
```cs
53+
using Microsoft.Azure.WebJobs;
54+
using Microsoft.Azure.WebJobs.Extensions.AzureCosmosDb.Mongo;
55+
using Microsoft.Extensions.Logging;
56+
using MongoDB.Bson;
57+
using MongoDB.Driver;
58+
using System;
59+
60+
namespace Sample
61+
{
62+
63+
[FunctionName("TriggerSample")]
64+
public static void TriggerRun(
65+
[CosmosDBMongoTrigger("vCoreDatabaseTrigger", "vCoreCollectionTrigger", ConnectionStringSetting = "vCoreConnectionStringTrigger")] ChangeStreamDocument<BsonDocument> doc,
66+
ILogger log)
67+
{
68+
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
69+
70+
log.LogInformation(doc.FullDocument.ToString());
71+
}
72+
}
73+
```
74+
75+
## Related articles
76+
77+
- [Azure Cosmos DB for MongoDB(vCore)](./cosmos-db/mongodb/vcore/introduction.md)
78+
- [Azure Azure Cosmos DB for MongoDB(vCore) bindings for Azure Functions](./azure/azure-functions/functions-bindings-mongodb-vcore-csharp-only)

0 commit comments

Comments
 (0)