Skip to content

Commit 555b6dd

Browse files
committed
Revamp cosmos-db/gremlin/quickstart-dotnet
1 parent 4c7b982 commit 555b6dd

File tree

3 files changed

+211
-9
lines changed

3 files changed

+211
-9
lines changed

articles/cosmos-db/gremlin/quickstart-dotnet.md

Lines changed: 207 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
2-
title: 'Quickstart: Library for .NET'
2+
title: 'Quickstart: Gremlin library for .NET'
33
titleSuffix: Azure Cosmos DB for Apache Gremlin
44
description: In this quickstart, connect to Azure Cosmos DB for Apache Gremlin using .NET. Then, create and traverse vertices and edges.
55
author: manishmsfte
66
ms.author: mansha
77
ms.reviewer: sidandrews
88
ms.service: cosmos-db
99
ms.subservice: apache-gremlin
10-
ms.topic: quickstart
10+
ms.topic: quickstart-sdk
1111
ms.date: 09/27/2023
1212
# CustomerIntent: As a .NET developer, I want to use a library for my programming language so that I can create and traverse vertices and edges in code.
1313
---
1414

15-
# Quickstart: Azure Cosmos DB for Apache Gremlin library for Python
15+
# Quickstart: Azure Cosmos DB for Apache Gremlin library for .NET
1616

1717
[!INCLUDE[Gremlin](../includes/appliesto-gremlin.md)]
1818

@@ -35,10 +35,212 @@ In this quickstart, you use the `Gremlin.Net` library to connect to a newly crea
3535

3636
[!INCLUDE[Cloud Shell](../../../includes/cloud-shell-try-it.md)]
3737

38-
## Create an API for Gremlin account and relevant resources
38+
## Setting up
39+
40+
This section walks you through creating an API for Gremlin account and setting up a .NET project to use the library to connect to the account.
41+
42+
### Create an API for Gremlin account
3943

4044
The API for Gremlin account should be created prior to using the .NET library. Additionally, it helps to also have the database and graph in place.
4145

4246
[!INCLUDE[Create account, database, and graph](includes/create-account-database-graph-cli.md)]
4347

44-
##
48+
### Create a new .NET console application
49+
50+
Create a .NET console application in an empty folder using your preferred terminal.
51+
52+
1. Open your terminal in an empty folder.
53+
54+
1. Use the `dotnet new` command specifying the **console** template.
55+
56+
```bash
57+
dotnet new console
58+
```
59+
60+
### Install the NuGet package
61+
62+
Add the `Gremlin.NET` NuGet package to the .NET project.
63+
64+
1. Use the `dotnet add package` command specifying the `Gremlin.Net` NuGet package.
65+
66+
```bash
67+
dotnet add package Gremlin.Net
68+
```
69+
70+
1. Build the .NET project using `dotnet build`.
71+
72+
```bash
73+
dotnet build
74+
```
75+
76+
Make sure that the build was successful with no errors. The expected output from the build should look something like this:
77+
78+
```output
79+
Determining projects to restore...
80+
All projects are up-to-date for restore.
81+
dslkajfjlksd -> \dslkajfjlksd\bin\Debug\net6.0\dslkajfjlksd.dll
82+
83+
Build succeeded.
84+
0 Warning(s)
85+
0 Error(s)
86+
```
87+
88+
### Configure environment variables
89+
90+
To use the *NAME* and *URI* values obtained earlier in this quickstart, persist them to new environment variables on the local machine running the application.
91+
92+
1. To set the environment variable, use your terminal to persist the values as `COSMOS_ENDPOINT` and `COSMOS_KEY` respectively.
93+
94+
```bash
95+
export COSMOS_GREMLIN_ENDPOINT="<account-name>"
96+
export COSMOS_GREMLIN_KEY="<account-key>"
97+
```
98+
99+
1. Validate that the environment variables were set correctly.
100+
101+
```bash
102+
printenv COSMOS_GREMLIN_ENDPOINT
103+
printenv COSMOS_GREMLIN_KEY
104+
```
105+
106+
## Code examples
107+
108+
- [Authenticate the client](#authenticate-the-client)
109+
- [Create vertices](#create-vertices)
110+
- [Create edges](#create-edges)
111+
- [Query vertices &amp; edges](#query-vertices--edges)
112+
113+
The code in this article connects to a database named `cosmicworks` and a graph named `products`. The code then adds vertices and edges to the graph before traversing the added items.
114+
115+
### Authenticate the client
116+
117+
Application requests to most Azure services must be authorized. For the API for Gremlin, use the *NAME* and *URI* values obtained earlier in this quickstart.
118+
119+
1. Open the **Program.cs** file.
120+
121+
1. Delete any existing content within the file.
122+
123+
1. Add a using block for the `Gremlin.Net.Driver` namespace.
124+
125+
:::code language="csharp" source="~/cosmos-db-apache-gremlin-dotnet-samples/001-quickstart/Program.cs" id="imports":::
126+
127+
1. Create `accountName` and `accountKey` string variables. Store the `COSMOS_GREMLIN_ENDPOINT` and `COSMOS_GREMLIN_KEY` environment variables as the values for each respective variable.
128+
129+
:::code language="csharp" source="~/cosmos-db-apache-gremlin-dotnet-samples/001-quickstart/Program.cs" id="environment_variables":::
130+
131+
1. Create a new instance of `GremlinServer` using the account's credentials.
132+
133+
:::code language="csharp" source="~/cosmos-db-apache-gremlin-dotnet-samples/001-quickstart/Program.cs" range="1-7" id="authenticate_client":::
134+
135+
1. Create a new instance of `GremlinClient` using the remote server credentials and the **GraphSON 2.0** serializer.
136+
137+
:::code language="csharp" source="~/cosmos-db-apache-gremlin-dotnet-samples/001-quickstart/Program.cs" range="9-12" id="authenticate_client":::
138+
139+
## Create vertices
140+
141+
Now that the application is connected to the account, use the standard Gremlin syntax to create vertices.
142+
143+
1. Use `SubmitAsync` to run a command server-side on the API for Gremlin account. Create a **product** vertex with the following properties:
144+
145+
| | Value |
146+
| --- | --- |
147+
| **label** | `product` |
148+
| **id** | `68719518371` |
149+
| **`name`** | `Kiama classic surfboard` |
150+
| **`price`** | `285.55` |
151+
| **`category`** | `surfboards` |
152+
153+
:::code language="csharp" source="~/cosmos-db-apache-gremlin-dotnet-samples/001-quickstart/Program.cs" range="1-3" id="create_vertices":::
154+
155+
1. Create a second **product** vertex with these properties:
156+
157+
| | Value |
158+
| --- | --- |
159+
| **label** | `product` |
160+
| **id** | `68719518403` |
161+
| **`name`** | `Montau Turtle Surfboard` |
162+
| **`price`** | `600.00` |
163+
| **`category`** | `surfboards` |
164+
165+
:::code language="csharp" source="~/cosmos-db-apache-gremlin-dotnet-samples/001-quickstart/Program.cs" range="9-11" id="create_vertices":::
166+
167+
1. Create a third **product** vertex with these properties:
168+
169+
| | Value |
170+
| --- | --- |
171+
| **label** | `product` |
172+
| **id** | `68719518409` |
173+
| **`name`** | `Bondi Twin Surfboard` |
174+
| **`price`** | `585.50` |
175+
| **`category`** | `surfboards` |
176+
177+
:::code language="csharp" source="~/cosmos-db-apache-gremlin-dotnet-samples/001-quickstart/Program.cs" range="5-7" id="create_vertices":::
178+
179+
## Create edges
180+
181+
Create edges using the Gremlin syntax to define relationships between vertices.
182+
183+
1. Create an edge from the `Montau Turtle Surfboard` product named **replaces** to the `Kiama classic surfboard` product.
184+
185+
:::code language="csharp" source="~/cosmos-db-apache-gremlin-dotnet-samples/001-quickstart/Program.cs" range="1-3" id="create_edges":::
186+
187+
> [!TIP]
188+
> This edge defintion uses the `g.V(['<partition-key>', '<id>'])` syntax. Alternatively, you can use `g.V('<id>').has('category', '<partition-key>')`.
189+
190+
1. Create another **replaces** edge from the same product to the `Bondi Twin Surfboard`.
191+
192+
:::code language="csharp" source="~/cosmos-db-apache-gremlin-dotnet-samples/001-quickstart/Program.cs" range="5-7" id="create_edges":::
193+
194+
## Query vertices &amp; edges
195+
196+
Use the Gremlin syntax to traverse the graph and discover relationships between vertices.
197+
198+
1. Traverse the graph and find all vertices that `Montau Turtle Surfboard` replaces.
199+
200+
:::code language="csharp" source="~/cosmos-db-apache-gremlin-dotnet-samples/001-quickstart/Program.cs" range="1-3" id="query_vertices_edges":::
201+
202+
1. Write to the console the static string `[CREATED PRODUCT]\t68719518403`.
203+
204+
:::code language="csharp" source="~/cosmos-db-apache-gremlin-dotnet-samples/001-quickstart/Program.cs" range="5" id="query_vertices_edges":::
205+
206+
1. Iterate over each matching vertex using a `foreach` loop and write to the console a message that starts with `[REPLACES PRODUCT]` and includes the matching product `id` field as a suffix.
207+
208+
:::code language="csharp" source="~/cosmos-db-apache-gremlin-dotnet-samples/001-quickstart/Program.cs" range="6-9" id="query_vertices_edges":::
209+
210+
## Run the code
211+
212+
Validate that your application works as expected by running the application. The application should execute with no errors or warnings. The output of the application includes data about the created and queried items.
213+
214+
1. Open the terminal in the .NET project folder.
215+
216+
1. Use `dotnet run` to run the application.
217+
218+
```bash
219+
dotnet run
220+
```
221+
222+
1. Observe the output from the application.
223+
224+
```output
225+
[CREATED PRODUCT] 68719518403
226+
[REPLACES PRODUCT] 68719518371
227+
[REPLACES PRODUCT] 68719518409
228+
```
229+
230+
## Clean up resources
231+
232+
When you no longer need the API for Gremlin account, delete the corresponding resource group.
233+
234+
1. Open your terminal in any folder.
235+
236+
1. Use `az group delete` to delete the resource group.
237+
238+
```azurecli-interactive
239+
az group delete \
240+
--name $resourceGroupName
241+
```
242+
243+
## Next step
244+
245+
> [!div class="nextstepaction"]
246+
> [Create and query data using Azure Cosmos DB for Apache Gremlin](tutorial-query.md)

articles/cosmos-db/gremlin/quickstart-nodejs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.author: mansha
77
ms.reviewer: sidandrews
88
ms.service: cosmos-db
99
ms.subservice: apache-gremlin
10-
ms.topic: quickstart
10+
ms.topic: quickstart-sdk
1111
ms.date: 09/27/2023
1212
# CustomerIntent: As a Node.js developer, I want to use a library for my programming language so that I can create and traverse vertices and edges in code.
1313
---
@@ -37,7 +37,7 @@ In this quickstart, you use the `gremlin` library to connect to a newly created
3737

3838
## Setting up
3939

40-
This section walks you through creating an API for Gremlin account an setting up a .NET project to use the library to connect to the account.
40+
This section walks you through creating an API for Gremlin account and setting up a .NET project to use the library to connect to the account.
4141

4242
### Create an API for Gremlin account
4343

articles/cosmos-db/gremlin/quickstart-python.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.author: mansha
77
ms.reviewer: sidandrews
88
ms.service: cosmos-db
99
ms.subservice: apache-gremlin
10-
ms.topic: quickstart
10+
ms.topic: quickstart-sdk
1111
ms.date: 09/27/2023
1212
# CustomerIntent: As a Python developer, I want to use a library for my programming language so that I can create and traverse vertices and edges in code.
1313
---
@@ -37,7 +37,7 @@ In this quickstart, you use the `gremlinpython` library to connect to a newly cr
3737

3838
## Setting up
3939

40-
This section walks you through creating an API for Gremlin account an setting up a .NET project to use the library to connect to the account.
40+
This section walks you through creating an API for Gremlin account and setting up a .NET project to use the library to connect to the account.
4141

4242
### Create an API for Gremlin account
4343

0 commit comments

Comments
 (0)