Managing chunks

mongo --host ip-172-31-91-37.ec2.internal:27017

mongos> use myShardedDB
switched to db myShardedDB

mongos> db.dropDatabase()
{
        "dropped" : "myShardedDB",
        "ok" : 1,
        "$clusterTime" : {
                "clusterTime" : Timestamp(1527838236, 32),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        },
        "operationTime" : Timestamp(1527838236, 32)
}

Enable sharding

mongos> sh.enableSharding('myShardedDB')
{
        "ok" : 1,
        "$clusterTime" : {
                "clusterTime" : Timestamp(1527838037, 5),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        },
        "operationTime" : Timestamp(1527838037, 5)
}

mongos> sh.shardCollection('myShardedDB.users', {age: 1})
{
        "collectionsharded" : "myShardedDB.users",
        "collectionUUID" : BinData(4,"mb3T0qfTQi2F5KKoopstFg=="),
        "ok" : 1,
        "$clusterTime" : {
                "clusterTime" : Timestamp(1527838042, 18),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        },
        "operationTime" : Timestamp(1527838042, 18)
}

Import the mock data

cd /home/hadoop/MongoDB
wget https://www.dropbox.com/s/338oehs4tesmhnt/chapter_5_mock_data.csv

mongoimport -h ip-172-31-91-37.ec2.internal:27017 --type csv --headerline -d myShardedDB -c users chapter_5_mock_data.csv

2018-06-01T07:28:56.767+0000    connected to: ip-172-31-91-37.ec2.internal:27017
2018-06-01T07:28:59.753+0000    [####################....] myShardedDB.users    3.46MB/4.04MB (85.6%)
2018-06-01T07:29:00.271+0000    [########################] myShardedDB.users    4.04MB/4.04MB (100.0%)
2018-06-01T07:29:00.271+0000    imported 100000 documents

Inspect the chunks

mongo --host ip-172-31-91-37.ec2.internal:27017

results matching ""

    No results matching ""