|
22 | 22 | # 2.2 - Create collection with custom IndexPolicy |
23 | 23 | # 2.3 - Create collection with offer throughput set |
24 | 24 | # 2.4 - Create collection with unique key |
| 25 | +# 2.5 - Create Collection with partition key |
| 26 | +# 2.6 - Create Collection with partition key V2 |
25 | 27 | # |
26 | 28 | # 3. Manage Collection Offer Throughput |
27 | 29 | # 3.1 - Get Collection performance tier |
@@ -165,12 +167,37 @@ def create_Container(client, id): |
165 | 167 |
|
166 | 168 | collection = client.CreateContainer(database_link, coll) |
167 | 169 | print('Collection with id \'{0}\' created'.format(collection['id'])) |
| 170 | + print('Partition Key - \'{0}\''.format(collection['partitionKey'])) |
168 | 171 |
|
169 | 172 | except errors.CosmosError as e: |
170 | 173 | if e.status_code == 409: |
171 | 174 | print('A collection with id \'{0}\' already exists'.format(collection['id'])) |
172 | 175 | else: |
173 | | - raise errors.HTTPFailure(e.status_code) |
| 176 | + raise errors.HTTPFailure(e.status_code) |
| 177 | + |
| 178 | + print("\n2.6 Create Collection - With Partition key V2") |
| 179 | + |
| 180 | + try: |
| 181 | + coll = { |
| 182 | + "id": "collection_partition_key_v2", |
| 183 | + "partitionKey": { |
| 184 | + "paths": [ |
| 185 | + "/field1" |
| 186 | + ], |
| 187 | + "kind": "Hash", |
| 188 | + "version": 2 |
| 189 | + } |
| 190 | + } |
| 191 | + |
| 192 | + collection = client.CreateContainer(database_link, coll) |
| 193 | + print('Collection with id \'{0}\' created'.format(collection['id'])) |
| 194 | + print('Partition Key - \'{0}\''.format(collection['partitionKey'])) |
| 195 | + |
| 196 | + except errors.CosmosError as e: |
| 197 | + if e.status_code == 409: |
| 198 | + print('A collection with id \'{0}\' already exists'.format(collection['id'])) |
| 199 | + else: |
| 200 | + raise errors.HTTPFailure(e.status_code) |
174 | 201 |
|
175 | 202 | @staticmethod |
176 | 203 | def manage_offer_throughput(client, id): |
|
0 commit comments