Skip to content

Commit b7cd5e9

Browse files
authored
Update partitioning.md
1 parent 784f350 commit b7cd5e9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,36 @@ Each physical shard consists of a set of replicas, also referred to as a replica
8686

8787
- For optimal performance, logical shards should be evenly distributed in storage and request volume across the physical shards of the cluster.
8888

89+
## How to shard a collection
90+
Consider the following document within the 'cosmicworks' database and 'employee' collection
91+
92+
```json
93+
{
94+
"firstName": "Steve",
95+
"lastName": "Smith",
96+
"companyName": "Microsoft",
97+
"division": "Azure",
98+
"subDivision": "Data & AI",
99+
"timeInOrgInYears": 7
100+
}
101+
```
102+
103+
If the firstName property has been determined to be shard key for the collection, the following command should be used to shard the employee collection after it has been created.
104+
```javascript
105+
use cosmicworks;
106+
sh.shardCollection("cosmicworks.employee", {"firstName": 1})
107+
```
108+
109+
The service does not index the shard key default. Once the collection has been sharded an index must be explicitly created on the shard key property.
110+
111+
```javascript
112+
use cosmicworks;
113+
db.runCommand({
114+
createIndexes: "employee",
115+
indexes: [{"key":{"firstName":1}, "name":"firstName_1", "enableLargeIndexKeys": true}],
116+
blocking: true
117+
})
118+
```
89119

90120
## Next steps
91121

0 commit comments

Comments
 (0)