|
1 | 1 | ---
|
2 |
| -title: Access system document properties vian Azure Cosmos DB Graph |
3 |
| -description: Learn how read and write Azure Cosmos DB system document properties via API for Gremlin |
| 2 | +title: Access system document properties |
| 3 | +titleSuffix: Azure Cosmos DB for Apache Gremlin |
| 4 | +description: Learn how to read and write system document properties using Azure Cosmos DB for Apache Gremlin. |
| 5 | +author: seesharprun |
| 6 | +ms.author: sidandrews |
| 7 | +ms.reviewer: mansha |
4 | 8 | ms.service: cosmos-db
|
5 | 9 | ms.subservice: apache-gremlin
|
6 | 10 | ms.topic: how-to
|
7 |
| -ms.date: 09/16/2021 |
8 |
| -author: manishmsfte |
9 |
| -ms.author: mansha |
| 11 | +ms.date: 02/08/2024 |
10 | 12 | ---
|
11 | 13 |
|
12 |
| -# System document properties |
| 14 | +# Access system document properties using Azure Cosmos DB for Apache Gremlin |
| 15 | + |
13 | 16 | [!INCLUDE[Gremlin](../includes/appliesto-gremlin.md)]
|
14 | 17 |
|
15 |
| -Azure Cosmos DB has [system properties](/rest/api/cosmos-db/databases) such as ```_ts```, ```_self```, ```_attachments```, ```_rid```, and ```_etag``` on every document. Additionally, Gremlin engine adds ```inVPartition``` and ```outVPartition``` properties on edges. By default, these properties are available for traversal. However, it's possible to include specific properties, or all of them, in Gremlin traversal. |
| 18 | +Azure Cosmos DB for Gremlin has [system properties](/rest/api/cosmos-db/databases) such as `_ts`, `_self`, `_attachments`, `_rid`, and `_etag` on every item. Additionally, Gremlin engine adds `inVPartition` and `outVPartition` properties on edges. By default, these properties are available for traversal. However, it's possible to include specific properties, or all of them, in Gremlin traversal. |
16 | 19 |
|
17 |
| -```console |
| 20 | +```gremlin |
18 | 21 | g.withStrategies(ProjectionStrategy.build().IncludeSystemProperties('_ts').create())
|
19 | 22 | ```
|
20 | 23 |
|
21 | 24 | ## E-Tag
|
22 | 25 |
|
23 |
| -This property is used for optimistic concurrency control. If application needs to break operation into a few separate traversals, it can use eTag property to avoid data loss in concurrent writes. |
| 26 | +This property is used for optimistic concurrency control. If an application needs to break an operation into separate traversals, use the eTag property to avoid data loss in concurrent writes. |
24 | 27 |
|
25 |
| -```console |
| 28 | +```gremlin |
26 | 29 | g.withStrategies(ProjectionStrategy.build().IncludeSystemProperties('_etag').create()).V('1').has('_etag', '"00000100-0000-0800-0000-5d03edac0000"').property('test', '1')
|
27 | 30 | ```
|
28 | 31 |
|
29 | 32 | ## Time-to-live (TTL)
|
30 | 33 |
|
31 |
| -If collection has document expiration enabled and documents have `ttl` property set on them, then this property will be available in Gremlin traversal as a regular vertex or edge property. `ProjectionStrategy` isn't necessary to enable time-to-live property exposure. |
| 34 | +If a graph has document expiration enabled and documents have `ttl` property set on them, then this property is available in Gremlin traversal as a regular vertex or edge property. `ProjectionStrategy` isn't necessary to enable time-to-live property exposure. |
| 35 | + |
| 36 | +- Use the following command to set time-to-live on a new vertex: |
32 | 37 |
|
33 |
| -* Use the following command to set time-to-live on a new vertex: |
| 38 | + ```gremlin |
| 39 | + g.addV(<ID>).property('ttl', <expirationTime>) |
| 40 | + ``` |
34 | 41 |
|
35 |
| - ```console |
36 |
| - g.addV(<ID>).property('ttl', <expirationTime>) |
37 |
| - ``` |
| 42 | + For example, a vertex created with the following traversal is automatically deleted after *123 seconds*: |
38 | 43 |
|
39 |
| - For example, a vertex created with the following traversal is automatically deleted after *123 seconds*: |
| 44 | + ```gremlin |
| 45 | + g.addV('vertex-one').property('ttl', 123) |
| 46 | + ``` |
40 | 47 |
|
41 |
| - ```console |
42 |
| - g.addV('vertex-one').property('ttl', 123) |
43 |
| - ``` |
| 48 | +- Use the following command to set time-to-live on an existing vertex: |
44 | 49 |
|
45 |
| -* Use the following command to set time-to-live on an existing vertex: |
| 50 | + ```gremlin |
| 51 | + g.V().hasId(<ID>).has('pk', <pk>).property('ttl', <expirationTime>) |
| 52 | + ``` |
46 | 53 |
|
47 |
| - ```console |
48 |
| - g.V().hasId(<ID>).has('pk', <pk>).property('ttl', <expirationTime>) |
49 |
| - ``` |
| 54 | +- Applying the time-to-live property on vertices doesn't automatically apply it to associated edges. This behavior occurs because edges are independent records in the database store. Use the following command to set time-to-live on vertices and all the incoming and outgoing edges of the vertex: |
50 | 55 |
|
51 |
| -* Applying time-to-live property on vertices does not automatically apply it to edges. Because edges are independent records in the database store. Use the following command to set time-to-live on vertices and all the incoming and outgoing edges of the vertex: |
| 56 | + ```gremlin |
| 57 | + g.V().hasId(<ID>).has('pk', <pk>).as('v').bothE().hasNot('ttl').property('ttl', <expirationTime>) |
| 58 | + ``` |
52 | 59 |
|
53 |
| - ```console |
54 |
| - g.V().hasId(<ID>).has('pk', <pk>).as('v').bothE().hasNot('ttl').property('ttl', <expirationTime>) |
55 |
| - ``` |
| 60 | +> [!NOTE] |
| 61 | +> You can set time to Live (TTL) on the container to `-1` or to **On (no default)** from the Azure portal. Then, the TTL is infinite for any item unless the item has a TTL value explicitly set. |
56 | 62 |
|
57 |
| -You can set TTL on the container to -1 or set it to **On (no default)** from Azure portal, then the TTL is infinite for any item unless the item has TTL value explicitly set. |
| 63 | +## Next step |
58 | 64 |
|
59 |
| -## Next steps |
60 |
| -* [Azure Cosmos DB Optimistic Concurrency](../faq.yml#how-does-the-api-for-nosql-provide-concurrency-) |
61 |
| -* [Time to Live (TTL)](../time-to-live.md) in Azure Cosmos DB |
| 65 | +> [!div class="nextstepaction"] |
| 66 | +> [Time to Live (TTL) in Azure Cosmos DB](../time-to-live.md) |
0 commit comments