Skip to content

Commit 0d53424

Browse files
committed
Revamp cosmos-db/gremlin/quickstart-nodejs
1 parent 58d9162 commit 0d53424

File tree

1 file changed

+64
-52
lines changed

1 file changed

+64
-52
lines changed

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

Lines changed: 64 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -123,86 +123,98 @@ Application requests to most Azure services must be authorized. For the API for
123123

124124
1. Import the `gremlin` module.
125125

126-
```javascript
127-
import gremlin from 'gremlin'
128-
```
126+
:::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="imports":::
129127

130128
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.
131129

132-
```javascript
133-
134-
```
130+
:::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="environment_variables":::
135131

136132
1. Use `PlainTextSaslAuthenticator` to create a new object for the account's credentials.
137133
138-
```javascript
139-
140-
```
134+
:::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="authenticate_client":::
141135
142-
1. Use `Client` to connect using the remote server credentials and the **GraphSON 2.0** serializer.
136+
1. Use `Client` to connect using the remote server credentials and the **GraphSON 2.0** serializer. Then, use `Open` to create a new connection to the server.
143137
144-
```javascript
145-
146-
```
138+
:::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="connect_client":::
147139
148-
1. TODO
140+
## Create vertices
149141
150-
```javascript
151-
152-
```
142+
Now that the application is connected to the account, use the standard Gremlin syntax to create vertices.
153143
154-
1. TODO
155144
156-
```javascript
157-
158-
```
145+
1. Use `submit` to run a command server-side on the API for Gremlin account. Create a **product** vertex with the following properties:
159146
160-
1. TODO
147+
| | Value |
148+
| --- | --- |
149+
| **label** | `product` |
150+
| **id** | `68719518371` |
151+
| **`name`** | `Kiama classic surfboard` |
152+
| **`price`** | `285.55` |
153+
| **`category`** | `surfboards` |
161154
162-
```javascript
163-
164-
```
155+
:::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="create_vertices_1":::
165156
166-
1. TODO
157+
1. Create a second **product** vertex with these properties:
167158
168-
```javascript
169-
170-
```
159+
| | Value |
160+
| --- | --- |
161+
| **label** | `product` |
162+
| **id** | `68719518403` |
163+
| **`name`** | `Montau Turtle Surfboard` |
164+
| **`price`** | `600.00` |
165+
| **`category`** | `surfboards` |
171166
172-
1. TODO
167+
:::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="create_vertices_2":::
173168
174-
```javascript
175-
176-
```
169+
1. Create a third **product** vertex with these properties:
177170
178-
1. TODO
171+
| | Value |
172+
| --- | --- |
173+
| **label** | `product` |
174+
| **id** | `68719518409` |
175+
| **`name`** | `Bondi Twin Surfboard` |
176+
| **`price`** | `585.50` |
177+
| **`category`** | `surfboards` |
179178
180-
```javascript
181-
182-
```
179+
:::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="create_vertices_3":::
183180
184-
1. TODO
181+
## Create edges
185182
186-
```javascript
187-
188-
```
183+
Create edges using the Gremlin syntax to define relationships between vertices.
189184
190-
1. TODO
185+
1. Create an edge from the `Montau Turtle Surfboard` product named **replaces** to the `Kiama classic surfboard` product.
191186
192-
```javascript
193-
194-
```
187+
:::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="create_edges_1":::
195188
196-
1. TODO
189+
> [!TIP]
190+
> This edge defintion uses the `g.V(['<partition-key>', '<id>'])` syntax. Alternatively, you can use `g.V('<id>').has('category', '<partition-key>')`.
197191
198-
```javascript
199-
200-
```
192+
1. Create another **replaces** edge from the same product to the `Bondi Twin Surfboard`.
193+
194+
:::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="create_edges_2":::
195+
196+
## Query vertices &amp; edges
197+
198+
Use the Gremlin syntax to traverse the graph and discover relationships between vertices.
199+
200+
1. Traverse the graph and find all vertices that `Montau Turtle Surfboard` replaces.
201+
202+
:::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="query_vertices_edges":::
201203
202-
1. TODO
204+
1. Write to the console the result of this traversal.
203205
204-
```javascript
205-
206+
:::code language="javascript" source="~/cosmos-db-apache-gremlin-javascript-samples/001-quickstart/app.js" id="output_vertices_edges":::
207+
208+
## Run the code
209+
210+
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.
211+
212+
1. Open the terminal in the Node.js project folder.
213+
214+
1. Use `npm <script>` to run the application. Observe the output from the application.
215+
216+
```bash
217+
npm start
206218
```
207219
208220
## Clean up resources

0 commit comments

Comments
 (0)