@@ -48,6 +48,8 @@ The following example shows a sample code to create a document with the system d
48
48
49
49
** JSON representation of the document**
50
50
51
+ ### [ .NET SDK V3] ( #tab/dotnetv3 )
52
+
51
53
``` csharp
52
54
DeviceInformationItem = new DeviceInformationItem
53
55
{
@@ -109,7 +111,57 @@ await migratedContainer.Items.ReadItemAsync<DeviceInformationItem>(
109
111
110
112
```
111
113
112
- For the complete sample on how to repartition the documents , see the [.Net samples ][1 ] GitHub repository .
114
+ ### [Java SDK V4](#tab/javav4)
115
+
116
+ ```java
117
+ static class Family {
118
+ public String id ;
119
+ public String firstName ;
120
+ public String lastName ;
121
+ public String _partitionKey ;
122
+
123
+ public Family (String id , String firstName , String lastName , String _partitionKey ) {
124
+ this .id = id ;
125
+ this .firstName = firstName ;
126
+ this .lastName = lastName ;
127
+ this ._partitionKey = _partitionKey ;
128
+ }
129
+ }
130
+
131
+ .. .
132
+
133
+ CosmosDatabase cosmosDatabase = cosmosClient .getDatabase (" testdb" );
134
+ CosmosContainer cosmosContainer = cosmosDatabase .getContainer (" testcontainer" );
135
+
136
+ // Create single item
137
+ Family family = new Family (" id-1" , " John" , " Doe" , " Doe" );
138
+ cosmosContainer .createItem (family , new PartitionKey (family ._partitionKey ), new CosmosItemRequestOptions ());
139
+
140
+ // Create items through bulk operations
141
+ family = new Family (" id-2" , " Jane" , " Doe" , " Doe" );
142
+ CosmosItemOperation createItemOperation = CosmosBulkOperations .getCreateItemOperation (family ,
143
+ new PartitionKey (family ._partitionKey ));
144
+ cosmosContainer .executeBulkOperations (Collections .singletonList (createItemOperation ));
145
+ ```
146
+
147
+ For the complete sample , see the [.Net samples ][1 ] GitHub repository .
148
+
149
+ ## Migrate the documents
150
+
151
+ While the container definition is enhanced with a partition key property , the documents within the container aren ’t auto migrated . Which means the system partition key property `/ _partitionKey ` path is not automatically added to the existing documents . You need to repartition the existing documents by reading the documents that were created without a partition key and rewrite them back with `_partitionKey ` property in the documents .
152
+
153
+ ## Access documents that don't have a partition key
154
+
155
+ Applications can access the existing documents that don ’t have a partition key by using the special system property called "PartitionKey .None ", this is the value of the non -migrated documents . You can use this property in all the CRUD and query operations . The following example shows a sample to read a single Document from the NonePartitionKey .
156
+
157
+ ```java
158
+ CosmosItemResponse <JsonNode > cosmosItemResponse =
159
+ cosmosContainer .readItem (" itemId" , PartitionKey .NONE , JsonNode .class );
160
+ ```
161
+
162
+ For the complete sample on how to repartition the documents , see the [Java samples ][2 ] GitHub repository .
163
+
164
+ -- -
113
165
114
166
## Compatibility with SDKs
115
167
@@ -135,4 +187,5 @@ If new items are inserted with different values for the partition key, querying
135
187
* If all you know is the number of vcores and servers in your existing database cluster , read about [estimating request units using vCores or vCPUs ](.. / convert - vcore - to - request - unit .md )
136
188
* If you know typical request rates for your current database workload , read about [estimating request units using Azure Cosmos DB capacity planner ](estimate - ru - with - capacity - planner .md )
137
189
138
- [1 ]: https : // github.com/Azure/azure-cosmos-dotnet-v3/tree/master/Microsoft.Azure.Cosmos.Samples/Usage/NonPartitionContainerMigration
190
+ [1 ]: https : // github.com/Azure/azure-cosmos-dotnet-v3/tree/master/Microsoft.Azure.Cosmos.Samples/Usage/NonPartitionContainerMigration
191
+ [2 ]: https : // github.com/Azure-Samples/azure-cosmos-java-sql-api-samples/tree/main/src/main/java/com/azure/cosmos/examples/nonpartitioncontainercrud
0 commit comments