"Server Selection Error" in "Chapter 3: Sharding Lab: Shard a Collection"

The following command is throwing a server selection timeout error:

mongoimport --port 26000 --ssl -u "m103-admin" -p "m103-pass" --file=/datasets/products.json -d "m103" -c "products"

and the error being thrown is:

2020-12-13T18:38:31.278+0000    error connecting to host: could not connect to server: server selection error: server selection timeout
current topology: Type: Single
Addr: localhost:26000, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection(localhost:26000[-121]) connection is closed

Please help me with this issue.

Thanks in advance.

I am not sure --ssl is needed.

I also think that you have to specify an authenticationDatabase.

Can you include the config file of the server and the mongoimport version?

It throwed an error regarding authentication when I didn’t use --ssl
Later, the above mentioned error is being thrown.

Here is the config file content for mongos which was given in the curriculum and said that I need not change it:

  configDB: csrs/localhost:27004
  keyFile: /var/mongodb/pki/m103-keyfile
  bindIp: localhost
  port: 26000
  destination: file
  path: /var/mongodb/logs/mongos.log
  logAppend: true
  fork: true

And the mongo version which when I checked with sh.status() is 4.0.5

Pls, Let me know if I have provided enough information for the issue to be resolved.
Thanks in advance.

–ssl i snot needed as steevej-1495 mentioned
Please show screenshot of mongoimport authentication error when you ran with athenticationDatabase
Santiago_Miranda was asking about mongoimport version
You can check by

mongoimport --version

Here is the mongoimport version @Santiago_Miranda

mongoimport version: v3.11.6-33-ge17e60defb
git version: e17e60defb78d6909cf8595594b434e23d2a5319
Go version: go1.13.10
   os: linux
   arch: amd64
   compiler: gc

@Ramachandra_37567, Here is the error when i have not used --ssl

2020-12-15T05:49:05.778+0000 error connecting to host: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.

I am saying that --ssl is need because according to earlier lecture videos the Config server and Shards are created using keyfile authentication. Hence, it would require --ssl to authenticate and perform any operation.

I’m not sure how old that version is, but the newer ones are using 100+, so if you’re not in a development environment I’d install the new database tools (mongoimport/export and dump/restore).

The environment I am using is the one that is provided within the webpage which is a virtual machine hosted on the Servers of MongoDB. Hence, I guess I won’t have software updating privileges.

I think this issue needs to be addressed by the MongoDB Staff.

@Sonali_Mamgain, I have seen you as the MongoDB Staff on some of the topics. Hence, I would like you to look into the issue I am facing an issue, which is briefed in the first post in this topic created by me.

Thanks in Advance.

Do you have a file named mi.bash in your IDE? Try to run it and let us know the result. Even better, post a screenshot of the IDE.

Basically, they typed the mongoimport command to run. I tried it and it works as is without any issues.

I have 2 theories of why it is not working.

1. Some processes are not running anymore

For unknown reasons, some of the processes are not running any more. Please provide screenshots for each of the following commands individually.

clear ; ps -aef | grep [m]ongos
clear ; ps -aef | grep [c]srs
clear ; ps -aef | grep [s]hard1
clear ; ps -aef | grep [s]hard2

2. You are not using the IDE and your setup is not correct

Post a screenshot of the IDE running mongoimport that shows the error message you are getting.

Hi @steevej-1495 , thanks for replying.

The environment I worked for that task/lab is not on my own PC, it is the IDE provided in the browser by MongoDB curriculum.

I do not see any mi.bash file in this IDE.

As instructed by you, I am providing the screenshots for the mentioned four commands:
(for theory 1):

(for theory 2):

Additional Info: The error is not being thrown immediately. Error is appearing after a few seconds 10 – 20 secs.

Everything is in place and looks good.

Connect to mongos and share the output of the command sh.status().

I even checked that, everything looked fine. Anyway, here it is…

bash-4.4# mongo --port 26000 -u "m103-admin" -p "m103-pass" 
MongoDB shell version v4.0.5
connecting to: mongodb://
Implicit session: session { "id" : UUID("3fa250c4-c126-4733-b2d3-87e424b791ab") }
MongoDB server version: 4.0.5
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
Questions? Try the support group
Server has startup warnings: 
2020-12-18T17:41:07.940+0000 I CONTROL  [main] ** WARNING: You are running this process as the root user, which is not recommended.
2020-12-18T17:41:07.940+0000 I CONTROL  [main] 
2020-12-18T17:41:07.940+0000 I CONTROL  [main] ** WARNING: This server is bound to localhost.
2020-12-18T17:41:07.940+0000 I CONTROL  [main] **          Remote systems will be unable to connect to this server. 
2020-12-18T17:41:07.940+0000 I CONTROL  [main] **          Start the server with --bind_ip <address> to specify which IP 
2020-12-18T17:41:07.940+0000 I CONTROL  [main] **          addresses it should serve responses from, or with --bind_ip_all to
2020-12-18T17:41:07.940+0000 I CONTROL  [main] **          bind to all interfaces. If this behavior is desired, start the
2020-12-18T17:41:07.940+0000 I CONTROL  [main] **          server with --bind_ip to disable this warning.
2020-12-18T17:41:07.940+0000 I CONTROL  [main] 
mongos> sh.status()
--- Sharding Status --- 
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("5fdce9b2954035a5fa2d3d15")
        {  "_id" : "shard1",  "host" : "shard1/localhost:27001,localhost:27002,localhost:27003",  "state" : 1 }
        {  "_id" : "shard2",  "host" : "shard2/localhost:27007,localhost:27008,localhost:27009",  "state" : 1 }
  active mongoses:
        "4.0.5" : 1
        Currently enabled: yes
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours: 
                No recent migrations
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }


Hi @Hitesh_Padal,

Sorry, I didn’t see your post earlier. Couple of things to note here:

  1. Replace --ssl from your command with --authenticationDatabase admin
  2. The file path in your command is incorrect. It’s /dataset/products.json

Let us know if the issue still persists.

~ Shubham

Thanks a lot @Shubham_Ranjan for rightly pointing out the mistake (my bad :sweat_smile:). Now the same line of code with the said corrections worked like magic. Once again thank you. :smiley:

It is funny how 12 days ago the same --ssl and --authenticationDatabase was mentioned without leading to a solution.

And reaffirmed 10 days ago:

1 Like