Skip to content

Commit 9649f06

Browse files
committed
Preview bindings for MongoDB
1 parent 30375cc commit 9649f06

8 files changed

+276
-234
lines changed

.openpublishing.publish.config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@
158158
"branch": "dev",
159159
"branch_mapping": {}
160160
},
161+
{
162+
"path_to_root": "azure-functions-mongodb-extension",
163+
"url": "https://github.com/Azure/Azure-functions-mongodb-extension",
164+
"branch": "main",
165+
"branch_mapping": {}
166+
},
161167
{
162168
"path_to_root": "azure-functions-nodejs-v4",
163169
"url": "https://github.com/Azure/azure-functions-nodejs-samples",

articles/azure-functions/functions-bindings-mongodb-vcore-csharp-only.md

Lines changed: 0 additions & 160 deletions
This file was deleted.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: Azure CosmosDB for MongoDB (vCore) Input Binding for Azure Functions
3+
description: Understand how to use Azure Cosmos DB for MongoDB (vCore) input binding to read items from the database.
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) input binding for Azure Functions
13+
14+
This article explains how to work with the [Azure Cosmos DB for MongoDB vCore](/azure/cosmos-db/mongodb/vcore/introduction) input binding in Azure Functions.
15+
16+
The Azure Cosmos DB for MongoDB (vCore) input binding lets you retretieve one or more items as documents from the database.
17+
18+
[!INCLUDE [functions-bindings-mongodb-vcore-preview](../../includes/functions-bindings-mongodb-vcore-preview.md)]
19+
20+
## Example
21+
22+
This example shows a Timer trigger function that uses an input binding to execute a periodic query against the database:
23+
24+
```csharp
25+
using Microsoft.Azure.WebJobs;
26+
using Microsoft.Azure.WebJobs.Extensions.AzureCosmosDb.Mongo;
27+
using Microsoft.Extensions.Logging;
28+
using MongoDB.Bson;
29+
using MongoDB.Driver;
30+
31+
namespace Sample
32+
{
33+
public static class Sample
34+
{
35+
[FunctionName("InputBindingSample")]
36+
public static async Task InputBindingRun(
37+
[TimerTrigger("*/5 * * * * *")] TimerInfo myTimer,
38+
[CosmosDBMongo("%vCoreDatabaseTrigger%", "%vCoreCollectionTrigger%", ConnectionStringSetting = "vCoreConnectionStringTrigger",
39+
QueryString = "%queryString%")] List<BsonDocument> docs,
40+
ILogger log)
41+
{
42+
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
43+
44+
foreach (var doc in docs)
45+
{
46+
log.LogInformation(doc.ToString());
47+
}
48+
}
49+
50+
}
51+
}
52+
```
53+
54+
The examples refer to a simple `TestClass` type:
55+
56+
```cs
57+
namespace Sample
58+
{
59+
public class TestClass
60+
{
61+
public string id { get; set; }
62+
public string SomeData { get; set; }
63+
}
64+
}
65+
```
66+
67+
## Attributes
68+
69+
This table describes the binding configuration properties of the `CosmosDBMongoTrigger` attribute.
70+
71+
|Parameter | Description|
72+
|---------|----------------------|
73+
|**FunctionId** | (Optional) The ID of the trigger function. |
74+
|**DatabaseName** | The name of the database being monitored by the trigger for changes. |
75+
|**CollectionName** | The name of the collection in the database being monitored by the trigger for changes.|
76+
|**ConnectionStringSetting** | The name of an app setting or setting collection that specifies how to connect to the Azure Cosmos DB account being monitored. |
77+
|**QueryString** | Defines the Mongo query expression used by the input binding return documents from the database. The query supports binding parameters. |
78+
79+
## Usage
80+
81+
You can use the `CosmosDBMongo` attribute to obtain and work directly with the [MongoDB client](https://mongodb.github.io/mongo-csharp-driver/2.8/apidocs/html/T_MongoDB_Driver_IMongoClient.htm) in your function code:
82+
83+
:::code language="csharp" source="~/azure-functions-mongodb-extension/Sample/Sample.cs" range="17-29" :::
84+
85+
## Related articles
86+
87+
- [Azure Cosmos DB for MongoDB (vCore)](/azure/cosmos-db/mongodb/vcore/introduction.md)
88+
- [Azure Cosmos DB for MongoDB (vCore) bindings for Azure Functions](functions-bindings-mongodb-vcore.md)
89+
- [Azure Cosmos DB for MongoDB (vCore) trigger for Azure Functions](functions-bindings-mongodb-vcore-trigger.md)
90+
- [Azure Cosmos DB for MongoDB(vCore) output binding for Azure Functions](functions-bindings-mongodb-vcore-output.md)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: Azure CosmosDB for MongoDB (vCore) Output Binding for Azure Functions
3+
description: Understand how to use Azure Cosmos DB for MongoDB (vCore) output to write new items to the database.
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) output binding for Azure Functions
13+
14+
This article explains how to work with the [Azure Cosmos DB for MongoDB vCore](/azure/cosmos-db/mongodb/vcore/introduction) output binding in Azure Functions.
15+
16+
The Azure Cosmos DB for MongoDB (vCore) output binding lets you write a new document to an Azure Cosmos DB for MongoDB(vCore) collection.
17+
18+
[!INCLUDE [functions-bindings-mongodb-vcore-preview](../../includes/functions-bindings-mongodb-vcore-preview.md)]
19+
20+
## Example
21+
22+
This example shows a Timer trigger function that uses `CosmosDBMongoCollector` to add an item to the database:
23+
24+
```csharp
25+
[FunctionName("OutputBindingSample")]
26+
public static async Task OutputBindingRun(
27+
[TimerTrigger("*/5 * * * * *")] TimerInfo myTimer,
28+
[CosmosDBMongo("%vCoreDatabaseBinding%", "%vCoreCollectionBinding%", ConnectionStringSetting = "vCoreConnectionStringBinding")] IAsyncCollector<TestClass> CosmosDBMongoCollector,
29+
ILogger log)
30+
{
31+
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
32+
33+
TestClass item = new TestClass()
34+
{
35+
id = Guid.NewGuid().ToString(),
36+
SomeData = "some random data"
37+
};
38+
await CosmosDBMongoCollector.AddAsync(item);
39+
}
40+
```
41+
42+
The examples refer to a simple `TestClass` type:
43+
44+
```cs
45+
namespace Sample
46+
{
47+
public class TestClass
48+
{
49+
public string id { get; set; }
50+
public string SomeData { get; set; }
51+
}
52+
}
53+
```
54+
55+
## Attributes
56+
57+
This table describes the binding configuration properties of the `CosmosDBMongoTrigger` attribute.
58+
59+
|Parameter | Description|
60+
|---------|----------------------|
61+
|**FunctionId** | (Optional) The ID of the trigger function. |
62+
|**DatabaseName** | The name of the database being monitored by the trigger for changes. |
63+
|**CollectionName** | The name of the collection in the database being monitored by the trigger for changes.|
64+
|**ConnectionStringSetting** | The name of an app setting or setting collection that specifies how to connect to the Azure Cosmos DB account being monitored. |
65+
|**CreateIfNotExists** | (Optional) When set to true, creates the targed database and collection when they don't already exist. |
66+
67+
## Usage
68+
69+
You can use the `CosmosDBMongo` attribute to obtain and work directly with the [MongoDB client](https://mongodb.github.io/mongo-csharp-driver/2.8/apidocs/html/T_MongoDB_Driver_IMongoClient.htm) in your function code:
70+
71+
:::code language="csharp" source="~/azure-functions-mongodb-extension/Sample/Sample.cs" range="17-29" :::
72+
73+
## Related articles
74+
75+
- [Azure Cosmos DB for MongoDB (vCore)](/azure/cosmos-db/mongodb/vcore/introduction.md)
76+
- [Azure Cosmos DB for MongoDB (vCore) bindings for Azure Functions](functions-bindings-mongodb-vcore.md)
77+
- [Azure Cosmos DB for MongoDB (vCore) trigger for Azure Functions](functions-bindings-mongodb-vcore-trigger.md)
78+
- [Azure Cosmos DB for MongoDB (vCore) input binding for Azure Functions](functions-bindings-mongodb-vcore-input.md)

0 commit comments

Comments
 (0)