|
| 1 | +title: Connect to your sharded cluster. |
| 2 | +ref: new-sharded-tsc-connect |
| 3 | +stepnum: 1 |
| 4 | +level: 4 |
| 5 | +content: | |
| 6 | + Connect :binary:`~bin.mongosh` to the :binary:`~bin.mongos` for your |
| 7 | + sharded cluster. Specify the ``host`` and ``port`` on which the |
| 8 | + ``mongos`` is running: |
| 9 | +
|
| 10 | + .. code-block:: javascript |
| 11 | +
|
| 12 | + mongosh --host <hostname> --port <port> |
| 13 | +--- |
| 14 | +title: Shard the collection. |
| 15 | +ref: new-sharded-tsc-create |
| 16 | +stepnum: 2 |
| 17 | +level: 4 |
| 18 | +content: | |
| 19 | + Use the :method:`~sh.shardCollection()` method to shard the |
| 20 | + collection. |
| 21 | +
|
| 22 | + Consider a time series collection with the following properties: |
| 23 | +
|
| 24 | + .. code-block:: javascript |
| 25 | +
|
| 26 | + db.createCollection( |
| 27 | + "deliverySensor", |
| 28 | + { |
| 29 | + timeseries: { |
| 30 | + timeField: "timestamp", |
| 31 | + metaField: "metadata", |
| 32 | + granularity: "minutes" |
| 33 | + } |
| 34 | + } |
| 35 | + ) |
| 36 | +
|
| 37 | + A sample document from the collection resembles: |
| 38 | +
|
| 39 | + .. code-block:: javascript |
| 40 | +
|
| 41 | + db.deliverySensor.insertOne( { |
| 42 | + "metadata": { "location": "USA", "vehicle": "truck" }, |
| 43 | + "timestamp": ISODate("2021-08-21T00:00:10.000Z"), |
| 44 | + "speed": 50 |
| 45 | + } ) |
| 46 | +
|
| 47 | + To shard the collection, run the following command: |
| 48 | +
|
| 49 | + .. code-block:: javascript |
| 50 | +
|
| 51 | + sh.shardCollection( "test.deliverySensor", { "metadata.location": 1 } ) |
| 52 | +
|
| 53 | + In this example, :method:`sh.shardCollection()`: |
| 54 | +
|
| 55 | + - Shards an existing time series collection named ``deliverySensor`` on |
| 56 | + the ``test`` database. |
| 57 | +
|
| 58 | + - Specifies the ``metadata.location`` field as the :ref:`shard key |
| 59 | + <shard-key>`. ``location`` is a sub-field of the collection's |
| 60 | + ``metaField``. |
| 61 | +
|
| 62 | + When the collection you specify to :method:`sh.shardCollection()` is |
| 63 | + a time series collection, you do not need to specify the |
| 64 | + :ref:`timeseries <method-sharded-time-series-collection-options>` |
| 65 | + option. |
| 66 | +
|
| 67 | +... |
0 commit comments