Environment setup
Visual Studio 2017
Azure Functions and Web Jobs Tools
Microsoft.NET.Sdk.Functions
Microsoft.Azure.WebJobs.Extensions.ComosDB
Cosmos DB
Azure Functions and Web Jobs Tools
Microsoft.NET.Sdk.Functions
Microsoft.Azure.WebJobs.Extensions.ComosDB
Cosmos DB
Database Name: "VehicleSpec"
Collection Name: "Vehicles"
Connection String: <CosmosDBConnectionString>
The Cosmos DB has 10 documents below.
Collection Name: "Vehicles"
Connection String: <CosmosDBConnectionString>
The Cosmos DB has 10 documents below.
Sample Code
1. Read a single document, looking up "id" from query string
2. local.settings.json
3. Read a single document, looking up "id" from route data
4. Extract specific json properties
5. Read multiple documents
1. Read a single document, looking up "id" from query string
VehicleList.cs
local.settings.json
GetDocument.cs
Sample request query and return
Point 1
Query string should be exact match
Point 2
When you set a wrong name of Cosmos DB database or collection, it returns "status": 400
Poitnt 3
For VehicleList class, type Guid is used, but string also works
2. local.settings.json
It is recommended that you develop Azure Functions locally using Visual Studio or Visual Studio Code. I do not find clarification in the official document, but you do not need to edit function.json by yourself, but it is automatically generated when you set up local.setting.json.
One thing I learned here is, if you do not want to describe the Cosmos DB setup parameters such as Database Name or Collection Name on Main method, you can pass it to local.settings.json. You can use Attribute property in between %, for example, databaseName: "%DatabaseName%" like below.
GetDocument.cs
local.settings.json
3. Read a single document, looking up "id" from route data
GetDocumentRoute.cs
Sample request query and return