Skip to content

Commit 041eda0

Browse files
authored
Update partitioning.md
1 parent 6d81e80 commit 041eda0

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

articles/cosmos-db/mongodb/vcore/partitioning.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,31 @@ use cosmicworks;
105105
sh.shardCollection("cosmicworks.employee", {"firstName": "hashed"})
106106
```
107107

108-
The service doesn't index the shard key by default. Once the collection is sharded an index must be explicitly created on the shard key property.
108+
The collection can also be sharded using an admin command:
109+
```javascript
110+
use cosmicworks;
111+
db.adminCommand({
112+
"shardCollection": "cosmicworks.employee",
113+
"key": {"firstName": "hashed"}
114+
})
115+
```
116+
117+
While it is not ideal to change the shard key after the collection has grown significantly in storage volume, the reshardCollection command can be used to alter the shard key.
118+
```javascript
119+
use cosmicworks;
120+
sh.reshardCollection("cosmicworks.employee", {"lastName": "hashed"})
121+
```
122+
123+
The collection can also be resharded using an admin command:
124+
```javascript
125+
use cosmicworks;
126+
db.adminCommand({
127+
"reshardCollection": "cosmicworks.employee",
128+
"key": {"lastName": "hashed"}
129+
})
130+
```
131+
132+
As a best practice, an index must be created on the shard key property.
109133

110134
```javascript
111135
use cosmicworks;

0 commit comments

Comments
 (0)