Skip to content

Commit 62c34cb

Browse files
author
Thomas Weiss
committed
Formatting fixes
1 parent b30f98b commit 62c34cb

File tree

3 files changed

+58
-92
lines changed

3 files changed

+58
-92
lines changed

articles/cosmos-db/how-to-define-unique-keys.md

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,19 @@ client.CreateDocumentCollectionAsync(UriFactory.CreateDatabaseUri("database"), n
5252

5353
## Use the .NET SDK V3
5454

55-
When creating a new container using the [.NET SDK v3](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/), a `UniqueKeyPolicy` object can be used to define unique key constraints.
55+
When creating a new container using the [.NET SDK v3](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/), use the SDK's fluent API to declare unique keys in a concise and readable way.
5656

5757
```csharp
58-
UniqueKey uniqueKey1 = new UniqueKey();
59-
uniqueKey1.Paths.Add("/firstName");
60-
uniqueKey1.Paths.Add("/lastName");
61-
uniqueKey1.Paths.Add("/emailAddress");
62-
63-
UniqueKey uniqueKey2 = new UniqueKey();
64-
uniqueKey1.Paths.Add("/address/zipCode");
65-
66-
UniqueKeyPolicy uniqueKeyPolicy = new UniqueKeyPolicy();
67-
uniqueKeyPolicy.UniqueKeys.Add(uniqueKey1);
68-
uniqueKeyPolicy.UniqueKeys.Add(uniqueKey2);
69-
70-
await client.GetDatabase("database").CreateContainerAsync(new ContainerProperties
71-
{
72-
Id = "container",
73-
PartitionKeyPath = "/myPartitionKey",
74-
UniqueKeyPolicy = uniqueKeyPolicy
75-
});
58+
await client.GetDatabase("database").DefineContainer(name: "container", partitionKeyPath: "/myPartitionKey")
59+
.WithUniqueKey()
60+
.Path("/firstName")
61+
.Path("/lastName")
62+
.Path("/emailAddress")
63+
.Attach()
64+
.WithUniqueKey()
65+
.Path("/address/zipCode")
66+
.Attach()
67+
.CreateIfNotExistsAsync();
7668
```
7769

7870
## Use the Java SDK

articles/cosmos-db/how-to-manage-indexing-policy.md

Lines changed: 36 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -371,45 +371,21 @@ az cosmosdb collection update \
371371

372372
The `DocumentCollection` object from the [.NET SDK v2](https://www.nuget.org/packages/Microsoft.Azure.DocumentDB/) exposes an `IndexingPolicy` property that lets you change the `IndexingMode` and add or remove `IncludedPaths` and `ExcludedPaths`.
373373

374-
Retrieve the container's details
375374

376375
```csharp
376+
// Retrieve the container's details
377377
ResourceResponse<DocumentCollection> containerResponse = await client.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri("database", "container"));
378-
```
379-
380-
Set the indexing mode to consistent
381-
382-
```csharp
378+
// Set the indexing mode to consistent
383379
containerResponse.Resource.IndexingPolicy.IndexingMode = IndexingMode.Consistent;
384-
```
385-
386-
Add an included path
387-
388-
```csharp
380+
// Add an included path
389381
containerResponse.Resource.IndexingPolicy.IncludedPaths.Add(new IncludedPath { Path = "/age/*" });
390-
```
391-
392-
Add an excluded path
393-
394-
```csharp
382+
// Add an excluded path
395383
containerResponse.Resource.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/name/*" });
396-
```
397-
398-
Add a spatial index
399-
400-
```csharp
384+
// Add a spatial index
401385
containerResponse.Resource.IndexingPolicy.SpatialIndexes.Add(new SpatialSpec() { Path = "/locations/*", SpatialTypes = new Collection<SpatialType>() { SpatialType.Point } } );
402-
```
403-
404-
Add a composite index
405-
406-
```csharp
386+
// Add a composite index
407387
containerResponse.Resource.IndexingPolicy.CompositeIndexes.Add(new Collection<CompositePath> {new CompositePath() { Path = "/name", Order = CompositePathSortOrder.Ascending }, new CompositePath() { Path = "/age", Order = CompositePathSortOrder.Descending }});
408-
```
409-
410-
Update container with changes
411-
412-
```csharp
388+
// Update container with changes
413389
await client.ReplaceDocumentCollectionAsync(containerResponse.Resource);
414390
```
415391

@@ -426,50 +402,26 @@ long indexTransformationProgress = container.IndexTransformationProgress;
426402

427403
The `ContainerProperties` object from the [.NET SDK v3](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/) (see [this Quickstart](create-sql-api-dotnet.md) regarding its usage) exposes an `IndexingPolicy` property that lets you change the `IndexingMode` and add or remove `IncludedPaths` and `ExcludedPaths`.
428404

429-
Retrieve the container's details
430405

431406
```csharp
407+
// Retrieve the container's details
432408
ContainerResponse containerResponse = await client.GetContainer("database", "container").ReadContainerAsync();
433-
```
434-
435-
Set the indexing mode to consistent
436-
437-
```csharp
409+
// Set the indexing mode to consistent
438410
containerResponse.Resource.IndexingPolicy.IndexingMode = IndexingMode.Consistent;
439-
```
440-
441-
Add an included path
442-
443-
```csharp
411+
// Add an included path
444412
containerResponse.Resource.IndexingPolicy.IncludedPaths.Add(new IncludedPath { Path = "/age/*" });
445-
```
446-
447-
Add an excluded path
448-
449-
```csharp
413+
// Add an excluded path
450414
containerResponse.Resource.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/name/*" });
451-
```
452-
453-
Add a spatial index
454-
455-
```csharp
415+
// Add a spatial index
456416
SpatialPath spatialPath = new SpatialPath
457417
{
458418
Path = "/locations/*"
459419
};
460420
spatialPath.SpatialTypes.Add(SpatialType.Point);
461421
containerResponse.Resource.IndexingPolicy.SpatialIndexes.Add(spatialPath);
462-
```
463-
464-
Add a composite index
465-
466-
```csharp
422+
// Add a composite index
467423
containerResponse.Resource.IndexingPolicy.CompositeIndexes.Add(new Collection<CompositePath> { new CompositePath() { Path = "/name", Order = CompositePathSortOrder.Ascending }, new CompositePath() { Path = "/age", Order = CompositePathSortOrder.Descending } });
468-
```
469-
470-
Update container with changes
471-
472-
```csharp
424+
// Update container with changes
473425
await client.GetContainer("database", "container").ReplaceContainerAsync(containerResponse.Resource);
474426
```
475427

@@ -482,6 +434,28 @@ ContainerResponse containerResponse = await client.GetContainer("database", "con
482434
long indexTransformationProgress = long.Parse(containerResponse.Headers["x-ms-documentdb-collection-index-transformation-progress"]);
483435
```
484436

437+
When defining a custom indexing policy while creating a new container, the SDK V3's fluent API lets you write this definition in a concise and efficient way:
438+
439+
```csharp
440+
await client.GetDatabase("database").DefineContainer(name: "container", partitionKeyPath: "/myPartitionKey")
441+
.WithIndexingPolicy()
442+
.WithIncludedPaths()
443+
.Path("/age/*")
444+
.Attach()
445+
.WithExcludedPaths()
446+
.Path("/name/*")
447+
.Attach()
448+
.WithSpatialIndex()
449+
.Path("/locations/*", SpatialType.Point)
450+
.Attach()
451+
.WithCompositeIndex()
452+
.Path("/name", CompositePathSortOrder.Ascending)
453+
.Path("/age", CompositePathSortOrder.Descending)
454+
.Attach()
455+
.Attach()
456+
.CreateIfNotExistsAsync();
457+
```
458+
485459
## Use the Java SDK
486460

487461
The `DocumentCollection` object from the [Java SDK](https://mvnrepository.com/artifact/com.microsoft.azure/azure-cosmosdb) (see [this Quickstart](create-sql-api-java.md) regarding its usage) exposes `getIndexingPolicy()` and `setIndexingPolicy()` methods. The `IndexingPolicy` object they manipulate lets you change the indexing mode and add or remove included and excluded paths.

articles/cosmos-db/how-to-time-to-live.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Use the following steps to enable time to live on a container with no expiration
3838

3939
## Enable time to live on a container using SDK
4040

41-
### <a id="dotnet-enable-noexpiry"></a>.NET SDK V2
41+
### <a id="dotnet-enable-noexpiry"></a>.NET SDK V2 (Microsoft.Azure.DocumentDB)
4242

4343
```csharp
4444
// Create a new container with TTL enabled and without any expiration value
@@ -52,7 +52,7 @@ DocumentCollection ttlEnabledCollection = await client.CreateDocumentCollectionA
5252
collectionDefinition);
5353
```
5454

55-
### <a id="dotnet-enable-noexpiry"></a>.NET SDK V3
55+
### <a id="dotnet-enable-noexpiry"></a>.NET SDK V3 (Microsoft.Azure.Cosmos)
5656

5757
```csharp
5858
// Create a new container with TTL enabled and without any expiration value
@@ -68,7 +68,7 @@ await client.GetDatabase("database").CreateContainerAsync(new ContainerPropertie
6868

6969
To set the time to live on a container, you need to provide a non-zero positive number that indicates the time period in seconds. Based on the configured TTL value, all items in the container after the last modified timestamp of the item `_ts` are deleted.
7070

71-
### <a id="dotnet-enable-withexpiry"></a>.NET SDK V2
71+
### <a id="dotnet-enable-withexpiry"></a>.NET SDK V2 (Microsoft.Azure.DocumentDB)
7272

7373
```csharp
7474
// Create a new container with TTL enabled and a 90 day expiration
@@ -82,7 +82,7 @@ DocumentCollection ttlEnabledCollection = await client.CreateDocumentCollectionA
8282
collectionDefinition;
8383
```
8484

85-
### <a id="dotnet-enable-withexpiry"></a>.NET SDK V3
85+
### <a id="dotnet-enable-withexpiry"></a>.NET SDK V3 (Microsoft.Azure.Cosmos)
8686

8787
```csharp
8888
// Create a new container with TTL enabled and a 90 day expiration
@@ -149,7 +149,7 @@ Use the following steps to enable time to live on an item:
149149
}
150150
```
151151

152-
### <a id="dotnet-set-ttl-item"></a>.NET SDK
152+
### <a id="dotnet-set-ttl-item"></a>.NET SDK (any)
153153

154154
```csharp
155155
// Include a property that serializes to "ttl" in JSON
@@ -190,7 +190,7 @@ const itemDefinition = {
190190

191191
You can reset the time to live on an item by performing a write or update operation on the item. The write or update operation will set the `_ts` to the current time, and the TTL for the item to expire will begin again. If you wish to change the TTL of an item, you can update the field just as you update any other field.
192192

193-
### <a id="dotnet-extend-ttl-item"></a>.NET SDK V2
193+
### <a id="dotnet-extend-ttl-item"></a>.NET SDK V2 (Microsoft.Azure.DocumentDB)
194194

195195
```csharp
196196
// This examples leverages the Sales Order class above.
@@ -204,7 +204,7 @@ readDocument.ttl = 60 * 30 * 30; // update time to live
204204
response = await client.ReplaceDocumentAsync(readDocument);
205205
```
206206

207-
### <a id="dotnet-extend-ttl-item"></a>.NET SDK V3
207+
### <a id="dotnet-extend-ttl-item"></a>.NET SDK V3 (Microsoft.Azure.Cosmos)
208208

209209
```csharp
210210
// This examples leverages the Sales Order class above.
@@ -219,7 +219,7 @@ await client.GetContainer("database", "container").ReplaceItemAsync(itemResponse
219219

220220
If time to live has been set on an item and you no longer want that item to expire, then you can get the item, remove the TTL field, and replace the item on the server. When the TTL field is removed from the item, the default TTL value assigned to the container is applied to the item. Set the TTL value to -1 to prevent an item from expiring and to not inherit the TTL value from the container.
221221

222-
### <a id="dotnet-turn-off-ttl-item"></a>.NET SDK V2
222+
### <a id="dotnet-turn-off-ttl-item"></a>.NET SDK V2 (Microsoft.Azure.DocumentDB)
223223

224224
```csharp
225225
// This examples leverages the Sales Order class above.
@@ -234,7 +234,7 @@ readDocument.ttl = null; // inherit the default TTL of the container
234234
response = await client.ReplaceDocumentAsync(readDocument);
235235
```
236236

237-
### <a id="dotnet-turn-off-ttl-item"></a>.NET SDK V3
237+
### <a id="dotnet-turn-off-ttl-item"></a>.NET SDK V3 (Microsoft.Azure.Cosmos)
238238

239239
```csharp
240240
// This examples leverages the Sales Order class above.
@@ -249,7 +249,7 @@ await client.GetContainer("database", "container").ReplaceItemAsync(itemResponse
249249

250250
To disable time to live on a container and stop the background process from checking for expired items, the `DefaultTimeToLive` property on the container should be deleted. Deleting this property is different from setting it to -1. When you set it to -1, new items added to the container will live forever, however you can override this value on specific items in the container. When you remove the TTL property from the container the items will never expire, even if there are they have explicitly overridden the previous default TTL value.
251251

252-
### <a id="dotnet-disable-ttl"></a>.NET SDK V2
252+
### <a id="dotnet-disable-ttl"></a>.NET SDK V2 (Microsoft.Azure.DocumentDB)
253253

254254
```csharp
255255
// Get the container, update DefaultTimeToLive to null
@@ -259,7 +259,7 @@ collection.DefaultTimeToLive = null;
259259
await client.ReplaceDocumentCollectionAsync(collection);
260260
```
261261

262-
### <a id="dotnet-disable-ttl"></a>.NET SDK V3
262+
### <a id="dotnet-disable-ttl"></a>.NET SDK V3 (Microsoft.Azure.Cosmos)
263263

264264
```csharp
265265
// Get the container, update DefaultTimeToLive to null

0 commit comments

Comments
 (0)