Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Not authorized on ___ to execute command" with mLab + MongoDB ^3.0

Tags:

npm

mongodb

mlab

Connects without a hitch, but on insert() throws me this error.

var MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
var url = 'mongodb://____:[email protected]:25565/heroku_w268n9pj';

MongoClient.connect(url, function(err, client) {
    assert.equal(null, err);
    db = client.db('temp');
    console.log("connected!");
    const collection = db.collection('temp');
    collection.insert([{
        something: please
    }
});

I saw some other answers regarding mLab accounts and credentials, but I just created a new admin account for this. Frustrating because it was working previously with v2.3.

like image 859
user61871 Avatar asked Dec 21 '17 01:12

user61871


1 Answers

When attempting to connect to an mlab database, you have to correctly specify the client. It's located at the end of your connection string, just after the final forward slash.

mlab_url = "mongodb://db_user_name:[email protected]:39725/heroku_sd1fp182?retryWrites=false"
client = MongoClient(url)


db = client["heroku_sd1fp182"]
collection = db["coinHack"]

You may also get the error:

This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.

Just add "?retryWrites=false" to your connection string, as shown above.

like image 132
Dr. Div Avatar answered Oct 26 '22 03:10

Dr. Div