Skip to content

MongoDB Setup

Dhruv Makwana edited this page Nov 30, 2024 · 1 revision

MongoDB Setup

  1. Check Installation Instructions
    Refer to the MongoDB Community Server installation instructions for detailed steps.

  2. Mongosh Installation Issue on Fedora
    Most of the time, Mongosh is installed automatically. However, on Fedora, there might be an issue with openssl, resulting in the following error:

    niklaus@fedora  ~  mongosh
    mongosh: OpenSSL configuration error:
    40A85B6A297F0000:error:030000A9:digital envelope routines:alg_module_init:unknown option:…/deps/openssl/openssl/crypto/evp/evp_cnf.c:61:name=rh-allow-sha1-signatures, value=yes
    

    Solution:
    Run the command sudo dnf swap mongodb-mongosh mongodb-mongosh-shared-openssl3. Ensure that you have installed mongodb-org and mongodb-org-server from the official repository before swapping mongodb-mongosh.

  3. Start MongoDB Service
    Start the mongod service by executing:

    sudo systemctl start mongod
  4. Create Root User for MongoDB
    Follow the instructions here to create a root user. Below is an example of how to create a user:

    db.createUser({
      user: "<name>",
      pwd: passwordPrompt(),      // Or "<cleartext password>"
      roles: [
        { role: "<role>", db: "<database>" } | "<role>",
        ...
      ],
    })
  5. Enable Authentication
    To require a username and password for connecting to the MongoDB server, modify the /etc/mongod.conf file as follows:

    security:
        authorization: "enabled"

    Then restart the service with:

    sudo systemctl restart mongod
  6. Add Environment variable Change the value of DATABASE_URI to mongodb://myDatabaseUser:D1fficultP%[email protected]:27017

Clone this wiki locally