Search code examples
mongodbmongodump

Mongodump connection refused error: No connection could be made because the target machine actively refused it


I'm trying to backup my local mongodb on windows 11. When I run the monogdump command I get this error:

 mongodump -h localhost --port 21017  -d aws_inventories --username username  --out dump3 --ssl
2023-07-04T10:59:18.460-0400    Failed: can't create session: could not connect to server: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: localhost:21017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp [::1]:21017: connectex: No connection could be made because the target machine actively refused it. }, ] }

That happens after I enter in the password manually.

However I can connect to the database using mongosh:

mongosh
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.5.4
Using MongoDB:          6.0.5
Using Mongosh:          1.5.4

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

------
   The server generated these startup warnings when booting
   2023-07-04T09:59:07.616-04:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
------

------
   Enable MongoDB's free cloud-based monitoring service, which will then receive and display
   metrics about your deployment (disk utilization, CPU, operation statistics, etc).

   The monitoring data will be available on a MongoDB website with a unique URL accessible to you
   and anyone you share the URL with. MongoDB may use this information to make product
   improvements and to suggest MongoDB products and deployment options to you.

   To enable free monitoring, run the following command: db.enableFreeMonitoring()
   To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
------

Warning: Found ~/.mongorc.js, but not ~/.mongoshrc.js. ~/.mongorc.js will not be loaded.
  You may want to copy or rename ~/.mongorc.js to ~/.mongoshrc.js.

How can I get past this error?


Solution

  • You have a typo:

    mongodump -h localhost --port 21017   # oops.   Should be 27017
    

    The reason mongosh works is because you are not specifying any options and by default it is connecting on port 27017.