-2

Below I list the directions I followed from the docs

Problem

  1. After following the docs listed below I am unable to access my database. I most definitely did not forget my password as I actually saved the query that I ran to create the user I will list the query I ran below.

  2. I get the following error when I try to connect my local host instance in MongoDB compass

connect ECONNREFUSED 127.0.0.1:27017
  1. I think the issue might lie in the fact that I was running these command in the mongodb compass mongosh terminal and not the mongod

use admin
db.createUser(
  {
    user: "max",
    pwd: "max",
    roles: [
      { role: "userAdminAnyDatabase", db: "admin" },
      { role: "readWriteAnyDatabase", db: "admin" }
    ]
  }
)

What I need Help with:

I need help accessing my local database and if possible setting up authentication on the schema

Below this line is the docs I followed


Start MongoDB without access control

Start a standalone mongod instance without access control. Open a terminal and run the following command as the mongod user:

mongod --port 27017 --dbpath /var/lib/mongodb

The mongod instance in this tutorial uses port 27017 and the /var/lib/mongodb data directory.

The tutorial assumes that the /var/lib/mongodb directory exists and is the default dbPath . You may specify a different data directory or port as needed.

TIP When mongod starts, it creates some system files in the /var/lib/mongodb directory. To ensure the system files have the correct ownership, follow this tutorial as the mongod user. If you start mongod as the root user you will have to update file ownership later.

  1. Connect to the instance Open a new terminal and connect to the database deployment with mongosh
mongosh --port 27017

If you are connecting to a different deployment, specify additional command line options, such as --host , as needed to connect.

  1. Create the user administrator IMPORTANT Localhost Exception You can create the user administrator either before or after enabling access control. If you enable access control before creating any user, MongoDB provides a localhost exception which allows you to create a user administrator in the admin database. Once created, you must authenticate as the user administrator to create additional users.

I made sure that I made a user

Using mongosh switch to the admin database add the myUserAdmin user with the userAdminAnyDatabase and readWriteAnyDatabase roles":

use admin
db.createUser(
  {
    user: "myUserAdmin",
    pwd: passwordPrompt(), // or cleartext password
    roles: [
      { role: "userAdminAnyDatabase", db: "admin" },
      { role: "readWriteAnyDatabase", db: "admin" }
    ]
  }
)
E_net4
  • 27,810
  • 13
  • 101
  • 139
Wayne
  • 660
  • 6
  • 16
  • Did you close the terminal where `mongod` runs? – Wernfried Domscheit Oct 01 '22 at 13:15
  • I am using a mongosh terminal. That is the new standard that comes with mongodb compass. I was told it should have all the functionality of the old terminal, in addition to newer features. link here: https://stackoverflow.com/questions/73911194/how-do-you-set-up-authentication-in-mongodb-compass-every-solution-uses-the-mon/73912410#73912410 – Wayne Oct 01 '22 at 19:43
  • 1
    I think you mix the MongoDB **server** `mongod` (or `mongos` in case of a sharded cluster) and the **client** - which can be the legacy `mongo` shell, the new `mongosh` shell or any other client driver/application like Mongo Compass. – Wernfried Domscheit Oct 01 '22 at 21:34
  • 1
    Totally agree with @WernfriedDomscheit about the confusion, tried to explain that previously. With respect to this issue - you need to take a look at the `mongod` log file to see if the server is receiving and rejecting the request. And including information like that here in your question is what would allow us to help you figure out and fix the problem. – user20042973 Oct 01 '22 at 23:04

2 Answers2

0

With respect to the technical issue, the error message that was provided (connect ECONNREFUSED 127.0.0.1:27017) suggests that the server is actively refusing the connection. Searching with this specific text surfaces lots of results that can probably help you solve the problem. This one, for example, suggests that one common reason for this error message is that the mongod process (the database itself) is not running. This is easy to test and reproduce, such as by trying to connect to a host and port where there is no mongod process running and listening. So I'd recommend taking a look at that question, or similar ones, to help troubleshoot and resolve your issue.

Also from the technical perspective, it is really important that we understand the different between the different processes associated with using MongoDB. As was noted in the comments:

  • The mongod process itself is the actual executable that needs to be up and running for the database to be accessible. Apart from starting this process with the appropriate parameters you don't do anything else with this. Typically this process needs to be --forked so that it does not stop when the command line is closed (which is what @Wernfried Domscheit was getting at in the comments). More information about this process is here in the documentation.
  • The shell(s) that are used to connect to and interact with the running database. The legacy one was mongo and the newer one (which is in Compass) is mongosh. This is an interface for connecting to and performing various tasks against the running database. This can include things like creating users or querying data.

This then bridges nicely toward the general advice part of this answer. It is important to keep in mind that, as of the time of writing, this question has been viewed more than 100 times. That represents a significant number of people who are volunteering their time in an attempt to help you without expecting anything in return. Said another way, we are trying to help you.

But in order to do so, we need to have an appropriate level of detail and context. It is great that you attempted to provide that information in the question itself, but ultimately it is not really enough for us to assist you effectively. Moreover, it is important to keep in mind that it is not a goal of this site (as far as I understand) to provide full tutorials or completely walkthrough configuring a new environment. Such guides can be found elsewhere, including in the documentation from the vendor that you linked. Having basic knowledge of the technology that you are working with is the foundation that allows for a "good" question. Such questions are those that allow us to help you in a focused and otherwise reasonable manner.

For MongoDB specifically, if you wanted to try to get additional support then you may try posting to the developer forums here.

The final point to make here is that it is worth considering what your ultimate goal here is. Operationally managing a database is often a task (or full job) that requires a lot of specific knowledge to perform correctly. This includes things like configuring the system properly to provide the high availability, data security, and other requirements needed by your application. Taking the time to learn these things yourself is certainly something that can be done, but the actual place that you should learn about them should probably be done primarily in a different place than this site. If you don't want to spend your time doing this, which is perfectly fine, then I would suggest looking into a hosted solution. Places like DigitalOcean and MongoDB itself offer such 'fully managed' solutions. Usually such solutions help extract away most of these underlying configuration/management details to help get you up and running faster with little upfront knowledge about operating databases being required. It may be something that is worth looking into, especially if you are just starting out on your MongoDB journey and have other tasks that you want to be focusing your time on.

E_net4
  • 27,810
  • 13
  • 101
  • 139
user20042973
  • 4,096
  • 2
  • 3
  • 14
0

I just uninstalled and reinstalled both MongoDB and MongoDB compass

Wayne
  • 660
  • 6
  • 16