I'm facing difficulties to import file into db

here is my command

mongoimport --host=locahost --port=27004 --username=m103-admin --collection=products --db=m103 --file=/dataset/products.json
Enter password:

2022-10-16T11:09:14.983+0000    error connecting to host: could not connect to server: server selection error: server selection timeout
current topology: Type: Single
Addr: locahost:27004, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection(locahost:27004[-121]) connection is closed


Can you connect to your mongodb?
Is is standalone or a replica?

i can connect to my DB , based on what i can see there is already two shards on the cluster but it seems that sharding haven't been activated on the DB , does it answer to your question ?

user@M103# mongod --host localhost --port 26000 -u m103-admin -p m103-pass
Error parsing command line: unrecognised option '--host'
try 'mongod --help' for more information
user@M103# mongo --username m103-admin --password m103-pass --authenticationDatabase admin --host localhost --port 26000
MongoDB shell version v4.0.5
connecting to: mongodb://localhost:26000/?authSource=admin&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("e803967b-1128-4c11-b102-eb3a092e265c") }
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: 
2022-10-16T13:31:21.600+0000 I CONTROL  [main] ** WARNING: You are running this process as the root user, which is not recommended.
2022-10-16T13:31:21.600+0000 I CONTROL  [main] 
2022-10-16T13:31:21.600+0000 I CONTROL  [main] ** WARNING: This server is bound to localhost.
2022-10-16T13:31:21.600+0000 I CONTROL  [main] **          Remote systems will be unable to connect to this server. 
2022-10-16T13:31:21.600+0000 I CONTROL  [main] **          Start the server with --bind_ip <address> to specify which IP 
2022-10-16T13:31:21.600+0000 I CONTROL  [main] **          addresses it should serve responses from, or with --bind_ip_all to
2022-10-16T13:31:21.600+0000 I CONTROL  [main] **          bind to all interfaces. If this behavior is desired, start the
2022-10-16T13:31:21.600+0000 I CONTROL  [main] **          server with --bind_ip to disable this warning.
2022-10-16T13:31:21.600+0000 I CONTROL  [main] 
mongos> sh.status()
--- Sharding Status --- 
  sharding version: {
        "_id" : 1,
        "minCompatibleVersion" : 5,
        "currentVersion" : 6,
        "clusterId" : ObjectId("634c07a8b97fabed9b036c79")
        {  "_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 }
                        shard key: { "_id" : 1 }
                        unique: false
                        balancing: true
                                shard1  1
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard1 Timestamp(1, 0) 

mongos> exit

You have a typo error in

after fixing the typo it still the same

user@M103# mongoimport --host=localhost --port=27004 --username=m103-admin --collection=products --db=m103 --file=/dataset/products.json
Enter password:

2022-10-16T16:55:28.457+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.

Not at all.

You had

now you have

It means the user/password is wrong for the given server. Or you are connecting to the wrong server. Since you have mentioned sharding in your of your post, I suspect you are connecting to the wrong server. You have to mongoimport into the mongos server. If I remember correctly the port for mongos is 26000.


i used the right port and the right DB sir , please can you share your command ?
this is m103 lab

Try to import into your mongos instance using port 26000 as per Steve’s suggestion
Check your lab instructions

1 Like

To see if you

please share the content of your mongos.conf. However, from the output you shared in I'm facing difficulties to import file into db - #3 by NOGOU_Brice, I see


which confirms without looking at your mongos.conf that the port number for your mongoimport should be 26000 rather than 27004.