Thanks for posting your question in the Microsoft Q&A forum.
If you need access to the entire document, you have a couple of options:
- Instead of using
CosmosDBTrigger
, which provides a simplified document, you can switch to using theCosmosDB
input binding. This allows you to specify the SQL query to retrieve the document. Here’s a basic example:[Function("log-available-agents")]
public async Task Run( [CosmosDB( databaseName: "%CosmosDatabaseId%", collectionName: "xyz", ConnectionStringSetting = "CosmosDbConnection", SqlQuery = "SELECT * FROM c")] IEnumerable<TodoItems> input, FunctionContext context) { foreach (var item in input) { // Process each TodoItems document } }
- If switching to `CosmosDB` binding is not feasible, you can enrich the data received from `CosmosDBTrigger` by querying Cosmos DB again within your function to fetch the complete document using the document ID retrieved from the trigger.
```csharp
[Function("log-available-agents")]
public async Task Run(
[CosmosDBTrigger(
databaseName: "%CosmosDatabaseId%",
collectionName: "xyz",
Connection = "CosmosDbConnection",
LeaseContainerName = "leases",
CreateLeaseContainerIfNotExists = true)] IReadOnlyList<Document> input,
FunctionContext context)
{
var cosmosClient = new CosmosClient("connectionString");
var container = cosmosClient.GetContainer("databaseId", "xyz");
foreach (var doc in input)
{
var id = doc.GetPropertyValue<string>("id");
var partitionKey = doc.GetPropertyValue<string>("partitionKey");
var response = await container.ReadItemAsync<TodoItems>(id, new PartitionKey(partitionKey));
var todoItem = response.Resource;
// Now `todoItem` should contain the complete document with all properties
}
}
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful