Skip to content

Commit 30375cc

Browse files
committed
Merge remote-tracking branch 'mongodb/vcore-functions' into mongodb
2 parents 820cdc2 + a95e48d commit 30375cc

File tree

3 files changed

+245
-0
lines changed

3 files changed

+245
-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: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
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: 5/8/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+
## Attributes
20+
21+
The following table explains the binding configuration properties that you set in the function.json file and the CosmosDBMongoTrigger attribute.
22+
23+
|Parameter | Description|
24+
|---------|----------------------|
25+
|**FunctionId** |Optional, the Id of trigger |
26+
|**DatabaseName** | The name of the database to which the parameter applies|
27+
|**CollectionName** | The name of the database to which the parameter applies|
28+
|**ConnectionStringSetting** | The name of the database to which the parameter applies|
29+
|**TriggerLevel** | The name of the database to which the parameter applies|
30+
31+
32+
## Usage
33+
34+
### Output
35+
36+
The Azure Cosmos DB for MongoDB(vCore) output binding lets you write a new document to an Azure Cosmos DB for MongoDB(vCore)
37+
38+
### Example
39+
40+
The examples refer to a simple `TestClass` type:
41+
42+
```cs
43+
namespace Sample
44+
{
45+
public class TestClass
46+
{
47+
public string id { get; set; }
48+
public string SomeData { get; set; }
49+
}
50+
}
51+
```
52+
### TimerTrigger trigger
53+
54+
```cs
55+
namespace Sample
56+
{
57+
public class TestClass
58+
{
59+
public string id { get; set; }
60+
public string SomeData { get; set; }
61+
}
62+
}
63+
```
64+
65+
```cs
66+
using Microsoft.Azure.WebJobs;
67+
using Microsoft.Azure.WebJobs.Extensions.AzureCosmosDb.Mongo;
68+
using Microsoft.Extensions.Logging;
69+
using MongoDB.Bson;
70+
using MongoDB.Driver;
71+
72+
namespace Sample
73+
{
74+
public static class Sample
75+
{
76+
[FunctionName("OutputBindingSample")]
77+
public static async Task OutputBindingRun(
78+
[TimerTrigger("*/5 * * * * *")] TimerInfo myTimer,
79+
[CosmosDBMongo("%vCoreDatabaseBinding%", "%vCoreCollectionBinding%", ConnectionStringSetting = "vCoreConnectionStringBinding")] IAsyncCollector<TestClass> CosmosDBMongoCollector,
80+
ILogger log)
81+
{
82+
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
83+
84+
TestClass item = new TestClass()
85+
{
86+
id = Guid.NewGuid().ToString(),
87+
SomeData = "some random data"
88+
};
89+
await CosmosDBMongoCollector.AddAsync(item);
90+
}
91+
}
92+
}
93+
94+
```
95+
## #Input
96+
97+
The Azure Cosmos DB for MongoDB(vCore) input binding lets you reretieve one or more Azure CosmosDB for MongoDB(vCore) documents.
98+
99+
### Example
100+
101+
The examples refer to a simple `TestClass` type:
102+
103+
```cs
104+
namespace Sample
105+
{
106+
public class TestClass
107+
{
108+
public string id { get; set; }
109+
public string SomeData { get; set; }
110+
}
111+
}
112+
```
113+
### TimerTrigger trigger
114+
115+
```cs
116+
namespace Sample
117+
{
118+
public class TestClass
119+
{
120+
public string id { get; set; }
121+
public string SomeData { get; set; }
122+
}
123+
}
124+
```
125+
126+
```cs
127+
using Microsoft.Azure.WebJobs;
128+
using Microsoft.Azure.WebJobs.Extensions.AzureCosmosDb.Mongo;
129+
using Microsoft.Extensions.Logging;
130+
using MongoDB.Bson;
131+
using MongoDB.Driver;
132+
133+
namespace Sample
134+
{
135+
public static class Sample
136+
{
137+
[FunctionName("InputBindingSample")]
138+
public static async Task InputBindingRun(
139+
[TimerTrigger("*/5 * * * * *")] TimerInfo myTimer,
140+
[CosmosDBMongo("%vCoreDatabaseTrigger%", "%vCoreCollectionTrigger%", ConnectionStringSetting = "vCoreConnectionStringTrigger",
141+
QueryString = "%queryString%")] List<BsonDocument> docs,
142+
ILogger log)
143+
{
144+
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
145+
146+
foreach (var doc in docs)
147+
{
148+
log.LogInformation(doc.ToString());
149+
}
150+
}
151+
152+
}
153+
}
154+
155+
```
156+
157+
## Related articles
158+
159+
- [Azure Cosmos DB for MongoDB(vCore)](/azure/cosmos-db/mongodb/vcore/introduction.md)
160+
- [Azure Azure Cosmos DB for MongoDB(vCore) bindings for Azure Functions](/azure/azure-functions/functions-bindings-overview-mongodb-vore-csharp-only)
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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: 5/8/2025
8+
ms.custom:
9+
- build-2025
10+
---
11+
12+
# Azure Cosmos DB for MongoDB(vCore) 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+
## Usage
45+
46+
The following example shows a C# Function that retrieves a single document when a document is updated/changed.
47+
48+
```cs
49+
using Microsoft.Azure.WebJobs;
50+
using Microsoft.Azure.WebJobs.Extensions.AzureCosmosDb.Mongo;
51+
using Microsoft.Extensions.Logging;
52+
using MongoDB.Bson;
53+
using MongoDB.Driver;
54+
using System;
55+
56+
namespace Sample
57+
{
58+
59+
[FunctionName("TriggerSample")]
60+
public static void TriggerRun(
61+
[CosmosDBMongoTrigger("vCoreDatabaseTrigger", "vCoreCollectionTrigger", ConnectionStringSetting = "vCoreConnectionStringTrigger")] ChangeStreamDocument<BsonDocument> doc,
62+
ILogger log)
63+
{
64+
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
65+
66+
log.LogInformation(doc.FullDocument.ToString());
67+
}
68+
}
69+
```
70+
71+
## Related articles
72+
73+
- [Azure Cosmos DB for MongoDB(vCore)](/azure/cosmos-db/mongodb/vcore/introduction.md)
74+
- [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)