Import fails - because of ssl perhaps?

so, I initiated data-bearing replica sets, initiated config replica set as well:

--- Sharding Status ---
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("5de3ea833fa49cb726ca8a46")
}
  shards:
  active mongoses:
        "3.4.2" : 1
 autosplit:
        Currently enabled: yes
...

Now trying to import:

$ mongoimport --port=26000 --username=mo_admin --collection=electro2 --db=test --headerline --type=csv --file="/dataset/electro2.csv" --ignoreBlanks
Enter password:

2019-12-01T17:11:48.673+0000 Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.
2019-12-01T17:11:48.674+0000 imported 0 documents
~

OK, then I try with --ssl thiking that may be the culprit:

mongoimport --port=26000 --username=mo_admin --collection=electro2 --db=test --headerline --type=csv --file="/dataset/electro2.csv" --ignoreBlanks --ssl ./data/shard_keyfile
Enter password:

2019-12-01T17:13:55.016+0000 error validating settings: incompatible options: --file and positional argument(s)
2019-12-01T17:13:55.016+0000 try ‘mongoimport --help’ for more information
~
Thoughts, suggestions? thnx

Hint: It’s authenticating on the test database. It needs to authenticate on the admin database.

thanks. I resolved it. You know what it was? I forgot to run
sh.addShard("Sharding_D01/…
sh.addShard("Sharding_D02/…
before attempting import.

hehe. Import is running now! then will add index, etc.

Interesting! Was that the port for mongos?

–port 26000 (just like it says in the import statement)

Anyway, while I have your attention, I ran into a different problem. I am trying to split the collections into 2 shards by zip code. I successfully created index on the ZIP_CODE field. And now I see this:

MongoDB Enterprise mongos> sh.shardCollection( “test.electro2”, { “ZIP_CODE_1”:1 } )
{ “code” : 20, “ok” : 0, “errmsg” : “sharding not enabled for db test” }

THoughts, suggestions?
Thanks a bunch

It’s been a while since I did this course so I don’t remember which port number belongs to what. Are you saying that 26000 is mongos? The reason I ask is because you got an authentication error which implies that internal authentication is on. So I would expect a different error if the shards weren’t added.

You need to enable sharding on the database with sh.enableSharding()

I have test database, which contains electro2 collection.
I need to split electro2 collection by zip code.
How would you write the enableShard statement?
thanks.
PS: just in case, data-bearing replicated servers live on ports 27001 – 27006, while config replica set lives on 26001 – 26003, and mongoS lives on 26000.

resolved. Here is what I have been missing:

sh.enableSharding("test.electro2")
sh.shardCollection("test.electro2", { ZIP_CODE: 1 } )

and that’s after I created the index. ZIP_CODE is name of a field, not name of index.

Now look at this beauty:

 databases:
        {  "_id" : "test",  "primary" : "Sharding_D01",  "partitioned" : true }
                test.electro2
                        shard key: { "ZIP_CODE" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                Sharding_D01    5
                                Sharding_D02    5
                        { "ZIP_CODE" : { "$minKey" : 1 } } -->> { "ZIP_CODE" : 10014 } on : Sharding_D02 Timestamp(2, 0)
                        { "ZIP_CODE" : 10014 } -->> { "ZIP_CODE" : 10024 } on : Sharding_D02 Timestamp(3, 0)
                        { "ZIP_CODE" : 10024 } -->> { "ZIP_CODE" : 10075 } on : Sharding_D02 Timestamp(4, 0)
                        { "ZIP_CODE" : 10075 } -->> { "ZIP_CODE" : 10458 } on : Sharding_D02 Timestamp(5, 0)
                        { "ZIP_CODE" : 10458 } -->> { "ZIP_CODE" : 11203 } on : Sharding_D02 Timestamp(6, 0)
                        { "ZIP_CODE" : 11203 } -->> { "ZIP_CODE" : 11217 } on : Sharding_D01 Timestamp(6, 1)
                        { "ZIP_CODE" : 11217 } -->> { "ZIP_CODE" : 11235 } on : Sharding_D01 Timestamp(1, 6)
                        { "ZIP_CODE" : 11235 } -->> { "ZIP_CODE" : 11377 } on : Sharding_D01 Timestamp(1, 7)
                        { "ZIP_CODE" : 11377 } -->> { "ZIP_CODE" : 11697 } on : Sharding_D01 Timestamp(1, 8)
                        { "ZIP_CODE" : 11697 } -->> { "ZIP_CODE" : { "$maxKey" : 1 } } on : Sharding_D01 Timestamp(1, 9)

Hi @Vicky_B,

I’m glad your issue got resolved. If you have any other query then please feel free to get back to us.

Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer