Use os.getenv("MONGODB_URI", "mongodb://127.0.0.1:27017") in django-mongodb-project template

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Trivial - P5
    • None
    • Affects Version/s: None
    • Component/s: django
    • None
    • Python Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      The django-mongodb-project template currently hardcodes the MongoDB connection URI. It should fall back to os.getenv("MONGODB_URI", "mongodb://127.0.0.1:27017") so that:

      • Developers can point at any MongoDB instance by setting MONGODB_URI in their environment (e.g. Atlas, a remote dev cluster, Docker)
      • The default mongodb://127.0.0.1:27017 is used when no env var is set, preserving current local-dev behavior

      Change

      In project_name/settings/base.py, replace the hardcoded URI with:

      import os
      
      DATABASES = {
          "default": {
              "ENGINE": "django_mongodb_backend",
              "HOST": os.getenv("MONGODB_URI", "mongodb://127.0.0.1:27017"),
          }
      }
      

      (Adjust field name — HOST or NAME — to match however the current settings parse the URI via django-mongodb-backend.)

      Acceptance Criteria

      • Setting MONGODB_URI=mongodb+srv://... in the environment connects to that cluster
      • Omitting MONGODB_URI defaults to mongodb://127.0.0.1:27017

            Assignee:
            Unassigned
            Reporter:
            Alex Clark
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: