0

I'm using Django(djongo) + MongoDB Altas(pymongo).

So I developed this web app locally where I use Javascript's fetch method to read and write data to MongoDB.

Example code:

fetch("https://127.0.0.1:8000/api/fetchValues")
    .then(response => response.json())
    .then(data => {
        //do something

Everything works fine locally, but when I deployed it to Heroku (and hardcoded the 127.0.0.1:8000 part with <appname>.heroku.com) the same fetch method returned [ ] instead of the actual values stored in MongoDB, although I got 200 OK code from it.

My settings.py file looks like this:

DATABASES = {
    'default': {
        'ENGINE': 'djongo',
        'CLIENT': {
            'host': 'mongodb+srv://<username>:<pass>@cluster0.74bck.mongodb.net/myFirstDatabase?retryWrites=true&w=majority',
            'authMechanism': 'SCRAM-SHA-1',
        }
    }
}

I've also used import django_heroku and django_heroku.settings(locals()) on top and bottom of my settings.py respectively.

I've migrated both using python manage.py and heroku run python manage.py (makemigrations/migrate of course).

I believe that it comes down to Heroku config vars and specifically DATABASE_URL which I cannot remove/edit. I've tried these steps:

but nothing worked. I've also made my own MONGODB_URI config var but at no use.

A fun fact is that when I used the Javascript fetch method above after deploying to Heroku (but with 127.0.0.1:8000) it worked fine, although I believe this wouldn't work on another machine except for my own.

Any help appreciated!

Spleef
  • 1

0 Answers0