How to move primary shard from one server to another server

Hi ,

I am working on chapter 3 and I have imported data in sharded cluster by connecting mongos.
i see it data is loaded and primary shard is “m103-repl-2”. but when i try to vailidate it is throwing error as below. Do i have to move primary shard to “m103-repl”
vagrant@m103:/shared/shard$ validate_lab_shard_collection

No documents found in m103.products - make sure you import the dataset into the
‘products’ collection in the ‘m103’ database.
vagrant@m103:/shared/shard$ validate_lab_shard_collection

Please find rs.status output.

=====================

MongoDB Enterprise mongos> sh.status()
— Sharding Status —
sharding version: {
“_id” : 1,
“minCompatibleVersion” : 5,
“currentVersion” : 6,
“clusterId” : ObjectId(“5c4922defe401b3b2410d221”)
}
shards:
{ “_id” : “m103-repl”, “host” : “m103-repl/192.168.103.100:27001,192.168.103.100:27002,192.168.103.100:27003”, “state” : 1 }
{ “_id” : “m103-repl-2”, “host” : “m103-repl-2/192.168.103.100:27004,192.168.103.100:27005,192.168.103.100:27006”, “state” : 1 }
active mongoses:
“3.6.9” : 2
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
1 : Success
databases:
{ “_id” : “config”, “primary” : “config”, “partitioned” : true }
config.system.sessions
shard key: { “_id” : 1 }
unique: false
balancing: true
chunks:
m103-repl 1
{ “_id” : { “$minKey” : 1 } } -->> { “_id” : { “$maxKey” : 1 } } on : m103-repl Timestamp(1, 0)
{ “_id” : “m103”, “primary” : “m103-repl-2”, “partitioned” : true }
m103.products
shard key: { “sku” : 1 }
unique: false
balancing: true
chunks:
m103-repl 1
m103-repl-2 2
{ “sku” : { “$minKey” : 1 } } -->> { “sku” : 23153496 } on : m103-repl Timestamp(2, 0)
{ “sku” : 23153496 } -->> { “sku” : 28928914 } on : m103-repl-2 Timestamp(2, 1)
{ “sku” : 28928914 } -->> { “sku” : { “$maxKey” : 1 } } on : m103-repl-2 Timestamp(1, 2)

The error message you get is No documents found in m103.products - make sure you import the dataset into the ‘products’ collection in the ‘m103’ database.

Did you check how many documents you have? How many?

Hi naseer561,

Yes it matters which is your primary shard as the Lab requires data to be present on primary shard i/e m103-repl and not m103-repl-2. Refer this link: movePrimary

And before sharding the collection make sure you have documents in the collection.

Kanika

Thanks Kanikasingla,It helped. After moving to m103-repl it worked.

Thanks.
Regards,
Naseer.

I tried this and DB is moved successfully but validation still failing
Any suggestions
Do we have to do any more steps after move
I even bounced all mongod still no resolution
Sharding collection was done on repl-2 before move
when i query sh.status() looks fine

2019-01-26T08:57:49.451+0000 [#######################.] m103.products 86.5MB/87.9MB (98.3%)
2019-01-26T08:57:50.940+0000 [########################] m103.products 87.9MB/87.9MB (100.0%)
2019-01-26T08:57:50.940+0000 imported 516784 documents
vagrant@m103:/dataset$ validate_lab_shard_collection

Incorrect number of documents imported - make sure you import the entire
dataset.
vagrant@m103:/dataset$ date
Sat Jan 26 09:33:13 UTC 2019
vagrant@m103:/dataset$ validate_lab_shard_collectioon

Incorrect number of documents imported - make sure you import the entire
dataset.
vagrant@m103:/dataset$ date
Sat Jan 26 09:59:37 UTC 2019
vagrant@m103:/dataset$

it looks like records count is not matching with validate script. you need re-import the data by dropping m103 database and create shard key and make sure primary database is m103-repl.

than validate your script.

Did you import products.json or products.part2.json?

Shard key exists
all validations look fine
Not clear what all documents to be imported
I need to load just the one under /dataset or one attached in handouts or both
I tried all options .none worked

             { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : m103-repl Timestamp(1, 0)
    {  "_id" : "m103",  "primary" : "m103-repl",  "partitioned" : true }
            m103.products
                    shard key: { "sku" : 1 }
                    unique: false
                    balancing: true
                    chunks:
                            m103-repl       1
                            m103-repl-2     2
                    { "sku" : { "$minKey" : 1 } } -->> { "sku" : 23153496 } on : m103-repl Timestamp(2, 0)
                    { "sku" : 23153496 } -->> { "sku" : 28928914 } on : m103-repl-2 Timestamp(2, 1)
                    { "sku" : 28928914 } -->> { "sku" : { "$maxKey" : 1 } } on : m103-repl-2 Timestamp(1, 2)

can you count the record in you shard?

Thanks for followup
Its completed
I repeated the steps from import
Went fine this time