mongoengine connection connectionerror with django rest framework

205 Views Asked by At

I am trying to build Django rest framework with MongoDB. So in my local its working. But in production, i'm using MongoLab as DB backend. But i'm not able make DB connection. I'm keep on getting DB connection authentication error.

command SON([('authenticate', 1), ('user', u'XXXXX'), ('nonce', u'XXXXX'), ('key', u'XXXXXX')]) failed: auth failed

Connection establishment code in settings file:

MONGODB_DATABASES = {
    "name": "XXXXX",
    "host": "XXX.mlab.com",
    "port": 33212,
    "username": "XXXX",
    "password": "XXXX"
}

mongoengine.connect(
    db=MONGODB_DATABASES['name'],
    host=MONGODB_DATABASES['host'],
    port=MONGODB_DATABASES['port'],
    username=MONGODB_DATABASES['username'],
    password=MONGODB_DATABASES['password'],
)

The MongoLab mongo version : mongod version: 3.6.6 (MMAPv1). Correct me what i did wrong

1

There are 1 best solutions below

0
On BEST ANSWER

I solved the issue by connecting the mongoengine with mLab like this

mongoengine.connect(
    "DB-Name",
    host="mongodb://username:[email protected]:33252/db-name"
)

Thanks Micheal J Roberts