Windows10 Community version problem

I am a student and we are supposed to use the Community version of MongoDB for our Web Application course. I am having a problem of running MongoDM on my Windows 10 64bit machine. I have installed the latest version 4.4.1 and the installation had no problems. However, when I issue a command mongo in the Command Prompt I get an error:

C:>mongo
MongoDB shell version v4.4.1
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn’t connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: No connection could be made because the target machine actively refused it. :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1

I have found a solution on the StackOverflow but it’s for the older versions:


How can have this fixed to have the MongoDB running, preferably with one click?

You have to start mongod before trying to connect with mongo shell.

So
C:>mongod
and then
C:>mongo
is the only solution?

No it is not. You could start mongod as a service, you could start mongod with a configuration file. You could connect to an Atlas cluster so you do not have to start mongod.

1 Like

How can I start mongod with a configuration file? It sounds more appealing to me.

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/

I also made a blog post with a Youtube video about how to get started with the MongoDB Atlas Free Tier which is enough for what you are trying to do. No credit card needed at all.

Cheers,
Maxime.

1 Like

Thanks, but it’s not going to work for me, because according to our course we are supposed to have the Custom settings, when installing the MongoDB.

When you installed what option you have clicked?

If You Installed MongoDB as a Windows Service

The MongoDB service is started upon successful installation [1].

If you followed above no need to start mongod
Just issue mongo and connect

In your case mongo command failed to connect as mongod is not up and running on default port 27017
So please check why it is not up
From task manager you can see mongod service under processes

1 Like

Here are the instructions we had:

  1. Download MongoDB Community
  2. Choose Setup Type -> Custom
  3. DO NOT install MongoDB as a service
  4. DO NOT install MongoDB Compass
  5. Navigate to the root directory of your C drive and create data folder
  6. Navigate inside the data folder and create db folder
  7. Test your installation by issuing the mongod command
  8. Make sure your PATH contains C:\Program Files\MongoDB\Server\4.4\bin

I’ve done all of that.

Ok Understood

When you issued just mongod at cmd prompt what happened?
Most likely it would have failed with missing directory

Please follow instructions from this link

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/#run-mongodb-from-cmd

It has the same result as what I was describing in the beginning when I open a separate command window and run mongod command first and then in another command window run mongo command.

C:>mongod
{“t”:{"$date":“2020-09-25T11:05:32.127-04:00”},“s”:“I”, “c”:“CONTROL”, “id”:23285, “ctx”:“main”,“msg”:“Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols ‘none’”}
{“t”:{"$date":“2020-09-25T11:05:32.134-04:00”},“s”:“W”, “c”:“ASIO”, “id”:22601, “ctx”:“main”,“msg”:“No TransportLayer configured during NetworkInterface startup”}
{“t”:{"$date":“2020-09-25T11:05:32.134-04:00”},“s”:“I”, “c”:“NETWORK”, “id”:4648602, “ctx”:“main”,“msg”:“Implicit TCP FastOpen in use.”}
{“t”:{"$date":“2020-09-25T11:05:32.136-04:00”},“s”:“I”, “c”:“STORAGE”, “id”:4615611, “ctx”:“initandlisten”,“msg”:“MongoDB starting”,“attr”:{“pid”:11568,“port”:27017,“dbPath”:“C:/data/db/”,“architecture”:“64-bit”,“host”:“IronCube”}}
{“t”:{"$date":“2020-09-25T11:05:32.136-04:00”},“s”:“I”, “c”:“CONTROL”, “id”:23398, “ctx”:“initandlisten”,“msg”:“Target operating system minimum version”,“attr”:{“targetMinOS”:“Windows 7/Windows Server 2008 R2”}}
{“t”:{"$date":“2020-09-25T11:05:32.136-04:00”},“s”:“I”, “c”:“CONTROL”, “id”:23403, “ctx”:“initandlisten”,“msg”:“Build Info”,“attr”:{“buildInfo”:{“version”:“4.4.1”,“gitVersion”:“ad91a93a5a31e175f5cbf8c69561e788bbc55ce1”,“modules”:,“allocator”:“tcmalloc”,“environment”:{“distmod”:“windows”,“distarch”:“x86_64”,“target_arch”:“x86_64”}}}}
{“t”:{"$date":“2020-09-25T11:05:32.137-04:00”},“s”:“I”, “c”:“CONTROL”, “id”:51765, “ctx”:“initandlisten”,“msg”:“Operating System”,“attr”:{“os”:{“name”:“Microsoft Windows 10”,“version”:“10.0 (build 19041)”}}}
{“t”:{"$date":“2020-09-25T11:05:32.137-04:00”},“s”:“I”, “c”:“CONTROL”, “id”:21951, “ctx”:“initandlisten”,“msg”:“Options set by command line”,“attr”:{“options”:{}}}
{“t”:{"$date":“2020-09-25T11:05:32.139-04:00”},“s”:“I”, “c”:“STORAGE”, “id”:22270, “ctx”:“initandlisten”,“msg”:“Storage engine to use detected by data files”,“attr”:{“dbpath”:“C:/data/db/”,“storageEngine”:“wiredTiger”}}
{“t”:{"$date":“2020-09-25T11:05:32.141-04:00”},“s”:“I”, “c”:“STORAGE”, “id”:22315, “ctx”:“initandlisten”,“msg”:“Opening WiredTiger”,“attr”:{“config”:“create,cache_size=3301M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],”}}
{“t”:{"$date":“2020-09-25T11:05:32.315-04:00”},“s”:“I”, “c”:“STORAGE”, “id”:22430, “ctx”:“initandlisten”,“msg”:“WiredTiger message”,“attr”:{“message”:"[1601046332:314976][11568:140709665395952], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 7 through 8"}}
{“t”:{"$date":“2020-09-25T11:05:32.512-04:00”},“s”:“I”, “c”:“STORAGE”, “id”:22430, “ctx”:“initandlisten”,“msg”:“WiredTiger message”,“attr”:{“message”:"[1601046332:511952][11568:140709665395952], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 8 through 8"}}
{“t”:{"$date":“2020-09-25T11:05:32.716-04:00”},“s”:“I”, “c”:“STORAGE”, “id”:22430, “ctx”:“initandlisten”,“msg”:“WiredTiger message”,“attr”:{“message”:"[1601046332:715948][11568:140709665395952], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Main recovery loop: starting at 7/4096 to 8/256"}}
{“t”:{"$date":“2020-09-25T11:05:33.095-04:00”},“s”:“I”, “c”:“STORAGE”, “id”:22430, “ctx”:“initandlisten”,“msg”:“WiredTiger message”,“attr”:{“message”:"[1601046333:94970][11568:140709665395952], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 7 through 8"}}
{“t”:{"$date":“2020-09-25T11:05:33.380-04:00”},“s”:“I”, “c”:“STORAGE”, “id”:22430, “ctx”:“initandlisten”,“msg”:“WiredTiger message”,“attr”:{“message”:"[1601046333:379508][11568:140709665395952], txn-recover: [WT_VERB_RECOVERY_PROGRESS] Recovering log 8 through 8"}}
{“t”:{"$date":“2020-09-25T11:05:33.565-04:00”},“s”:“I”, “c”:“STORAGE”, “id”:22430, “ctx”:“initandlisten”,“msg”:“WiredTiger message”,“attr”:{“message”:"[1601046333:565509][11568:140709665395952], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Set global recovery timestamp: (0, 0)"}}
{“t”:{"$date":“2020-09-25T11:05:33.566-04:00”},“s”:“I”, “c”:“STORAGE”, “id”:22430, “ctx”:“initandlisten”,“msg”:“WiredTiger message”,“attr”:{“message”:"[1601046333:565509][11568:140709665395952], txn-recover: [WT_VERB_RECOVERY | WT_VERB_RECOVERY_PROGRESS] Set global oldest timestamp: (0, 0)"}}
{“t”:{"$date":“2020-09-25T11:05:33.806-04:00”},“s”:“I”, “c”:“STORAGE”, “id”:4795906, “ctx”:“initandlisten”,“msg”:“WiredTiger opened”,“attr”:{“durationMillis”:1665}}
{“t”:{"$date":“2020-09-25T11:05:33.809-04:00”},“s”:“I”, “c”:“RECOVERY”, “id”:23987, “ctx”:“initandlisten”,“msg”:“WiredTiger recoveryTimestamp”,“attr”:{“recoveryTimestamp”:{"$timestamp":{“t”:0,“i”:0}}}}
{“t”:{"$date":“2020-09-25T11:05:33.829-04:00”},“s”:“I”, “c”:“STORAGE”, “id”:22262, “ctx”:“initandlisten”,“msg”:“Timestamp monitor starting”}
{“t”:{"$date":“2020-09-25T11:05:33.901-04:00”},“s”:“W”, “c”:“CONTROL”, “id”:22120, “ctx”:“initandlisten”,“msg”:“Access control is not enabled for the database. Read and write access to data and configuration is unrestricted”,“tags”:[“startupWarnings”]}
{“t”:{"$date":“2020-09-25T11:05:33.903-04:00”},“s”:“W”, “c”:“CONTROL”, “id”:22140, “ctx”:“initandlisten”,“msg”:“This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning”,“tags”:[“startupWarnings”]}
{“t”:{"$date":“2020-09-25T11:05:33.922-04:00”},“s”:“I”, “c”:“STORAGE”, “id”:20536, “ctx”:“initandlisten”,“msg”:“Flow Control is enabled on this deployment”}
{“t”:{"$date":“2020-09-25T11:05:34.204-04:00”},“s”:“I”, “c”:“FTDC”, “id”:20625, “ctx”:“initandlisten”,“msg”:“Initializing full-time diagnostic data capture”,“attr”:{“dataDirectory”:“C:/data/db/diagnostic.data”}}
{“t”:{"$date":“2020-09-25T11:05:34.210-04:00”},“s”:“I”, “c”:“NETWORK”, “id”:23015, “ctx”:“listener”,“msg”:“Listening on”,“attr”:{“address”:“127.0.0.1”}}
{“t”:{"$date":“2020-09-25T11:05:34.210-04:00”},“s”:“I”, “c”:“NETWORK”, “id”:23016, “ctx”:“listener”,“msg”:“Waiting for connections”,“attr”:{“port”:27017,“ssl”:“off”}}

C:>mongo
MongoDB shell version v4.4.1
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“93e33731-1848-4a22-aa76-a9b6f6e140cb”) }
MongoDB server version: 4.4.1

The server generated these startup warnings when booting:

    2020-09-25T11:05:33.901-04:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
    2020-09-25T11:05:33.903-04:00: This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning

    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()

Your log clearly shows it is waiting for connections

ctx”:“listener”,“msg”:“Waiting for connections”,“attr”:{“port”:27017,“ssl”:“off”}}

You should be able to connect.Is that mongo snapshot full?.It says connecting

You can ignore those startup warnings.By default ACL is not enabled
You have to mention in yor config file or use --auth parameter if you are starting mongod on command line

Another way to start a simple mongod on your system is to choose different port and dbpath
mongod --port 28000 --dbpath “C:/…/…” give some valid path
Once mongod is up open another terminal and connect using
mongo --port 28000

I think you are failing to understand that I can connect, it’s just an awkward way of connection. I cannot connect to a database using just mongo command, unlike my classmates who use UNIX-based OSes. Or I don’t understand what you are trying to do.

Your first post shows mongo failed to connect

Your last but one post says you are getting same results as first post
What i understood is you are facing issues in connecting to mongod
Now i understand what you meant by “awkward way of connection”
On one session you are starting mongod and in another session you are trying to connect using mongo which you do not want
That is how it works in Windows
If you have mongod running as service you don’t need to start mongod eveytime
Just go to cmd prompt and run mongo.It will connect
On Unix it uses fork option so your mongod will be running in the background
That is why your classmates don’t have to start mongod everytime and can connect just by issuing mongo

Hope it is clear now

You can connect with just mongo if you try to connect to a running mongod. It looks like, in your case, no mongod is running on your local host at default port 27017. That is why you have to start it.

O.K. Now I got it. Thank you very much!