djangomongodbmongodb-atlasdjongo

How to connect Django ORM to mongo atlas?


I am trying to connect my django instance to a mongo db cluster using django. I have checked from various sources and the way it is getting closer to work is:

DATABASES = {
    'default': {
        'ENGINE': 'djongo',
        'NAME': 'test',
        'HOST': 'mongodb+srv://mongo_usr:' + urllib.parse.quote('mypassword') + '@domain_assigned.mongodb.net/test?ssl=true&ssl_cert_reqs=CERT_NONE&retryWrites=true',
        'ENFORCE_SCHEMA': False
    }
}

It truly finds the endpoint but I am getting a weird error:

pymongo.errors.ServerSelectionTimeoutError: connection closed,connection closed,connection closed

has anyone fixed this before?


Solution

  • I just setup Djongo and MongoDB Atlas with the following:

    DATABASES = {
            'default': {
            'ENGINE': 'djongo',
            'NAME': '<db name>',
            'HOST': 'mongodb+srv://<db username>:<db password>@....mongodb.net/test?retryWrites=true',
            'USER': '<db username>',
            'PASSWORD': '<db password>',
        }
    }
    

    Hope that helps!