How to connect Django ORM to mongo atlas?

前端 未结 5 598
情深已故
情深已故 2020-12-21 10:41

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:

5条回答
  •  一整个雨季
    2020-12-21 11:17

    Install djongo package using pip install djongo.

    Make sure you import following module:

    import urllib
    

    Setup database settings.

    DATABASES = {
        'default': {
            'ENGINE': 'djongo',
            'NAME': '',
            'HOST': "mongodb+srv://:" +
                    urllib.parse.quote_plus("") +
                    "@........mongodb.net/test?retryWrites=true&ssl=true&ssl_cert_reqs=CERT_NONE&w=majority",
        }
    }
    

    Substitute db_username, db_name and db_password with your credentials.

    Also edit the host name given by Mongo Atlas.

提交回复
热议问题