0

I managed to get djongo working in my local computer but when I push it to production, I need to set up an admin account for mongo so that my DB doesnt get hacked (again, sigh). Ive searched for a solution for a couple of days, without success.

This is currently the code I have, but its not working:

DATABASES = {
    'default': {
        'ENGINE': 'djongo',
        'NAME': 'db_name',
        'HOST': 'localhost',
        'USERNAME': 'username',
        'PASSWORD': 'password',
    }
}

1) How can I configure djongo to access a DB with a username/password? I am only getting errors telling me that it wasnt able to log in to mongo.

2) Ive read a bit about "mongoengine", would you recommend I use that instead of djongo? Why?

1 Answers1

3

Use this format for the Database Configuration

DATABASES = {
    'default': {
        "ENGINE": "djongo",
        "CLIENT": {
            "host": "mongodb+srv://<user_name>:<password>@<host_url>/?retryWrites=true&w=majority",
            "username": "<user_name>",
            "password": "<password>",
            "name": "<db_name>",
            "authMechanism": "SCRAM-SHA-1", #Add this line if you are using Mongo Atlas Cloud DB
        },
    }
}
hari19
  • 95
  • 8