Failed: Cannot accept sharding commands if sharding state has not been initialized with a shardIdentity document

I am getting this error when trying to insert data into the collection:

vagrant@m103:~$ mongoimport --drop /dataset/products.json --port 26000 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin” --db m103 --collection products
2019-07-07T05:23:26.756+0000 connected to: localhost:26000
2019-07-07T05:23:26.757+0000 dropping: m103.products
2019-07-07T05:23:26.816+0000 Failed: Cannot accept sharding commands if sharding state has not been initialized with a shardIdentity document
2019-07-07T05:23:26.816+0000 imported 0 documents

Hi @Leander_25955,

Please check if all your mongods and mongos are up and running.
If all processes are started already, please share the sh.status() output.

Please let me know, if you have any questions.

Thanks,
Sonali

Yes I have checked and all my mongod’s are running.

The output of sh.status is as follows:

MongoDB Enterprise mongos> sh.status()
— Sharding Status —
sharding version: {
“_id” : 1,
“minCompatibleVersion” : 5,
“currentVersion” : 6,
“clusterId” : ObjectId(“5d208bce2117bedcd4d1c820”)
}
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.12” : 1
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 5
Last reported error: Could not find host matching read preference { mode: “primary” } for set m103-repl
Time of Reported error: Sun Jul 07 2019 05:03:38 GMT+0000 (UTC)
Migration Results for the last 24 hours:
No recent migrations
databases:
{ “_id” : “applicationData”, “primary” : “m103-repl”, “partitioned” : false }
{ “_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”, “partitioned” : true }
{ “_id” : “testDatabase”, “primary” : “m103-repl”, “partitioned” : false }

Hi @Leander_25955,

Please check the nodes in m103-repl replica Set.

You need to check the primary and secondaries are up and running and also check that sharding is enabled for m103-repl Replica Set.

Please let me know, if you have any questions.

Thanks,
Sonali