Heroku Express + Postgres addon requires elevated privileges - postgresql

[2018-05-16 08:27:12.979] [ERROR] server - Pipe
postgres://xnmcmqfirrdzkg:638d94fcd7aa5178e1054f0ff604613826033d5e8845fb42614c17a3d386823a#ec2-107-21-126-193.compute-1.amazonaws.com:5432/d5l5g60nk6l27a
requires elevated privileges
I'm trying to deploy server Express + Sequelize + Postgres on Heroku.
if (config.use_env_variable) {
var sequelize = new Sequelize(process.env[config.use_env_variable]);
}
else {
config.logging = function (str) {
log4js.getLogger("sequelize").info(str);
}
var sequelize = new Sequelize(config.database, config.username, config.password, config);
}
The data's credential is set at default. I tried searching on the internet but there is no one having the same problem with me.

I am. But I have not been able to figure it out yet. And the docs I have been provided are more than two years old.

Related

How to connect Mongolab with MongoDb.Driver

i'm testing mongolab with .netCore using MongoDb.Driver.
I have this connection string
mongodb://<dbuser>:<dbpassword>#mymongolaburl:46367/somedatabase
And i'm connecting this way
var connectionString = #"mongodb://<dbuser>:<dbpassword>#mymongolaburl:46367/somedatabase";
var databaseName = "somedatabase";
var client = new MongoClient(connectionString);
if (client != null)
{
_database = client.GetDatabase(databaseName);
_database.GetCollection<User>("User").InsertOne(new User {Name="Luke Skywalker" });
}
It is not working 'cause it says the database name is invalid, if i use the connection string without the database name
mongodb://<dbuser>:<dbpassword>#mymongolaburl:46367
I get a timeout execption.
I Already connected to database using Robo 3T.
Thanks in advance.
After one day i found how to do that in this link
The The solution is to specify which is database in the connection string
mongodb://<dbuser>:<dbpassword>#mymongolaburl:46367/?authSource=somedatabase
Thank you!

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

Connects without a hitch, but on insert() throws me this error.
var MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
var url = 'mongodb://____:____#ds125565.mlab.com: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.
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:db_password#ds139725.mlab.com: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.

Authenticating while connecting to multiple database using mongoose

I have set up auth in my MongoDB as mentioned here. Initially, in my project I was accessing a single database say, firstdb from mongoose using
let url = "mongodb://localhost:27017/firstdb";
let options = {
server:{
socketOptions:{
keepAlive:120
}
},
user:"username1",
pass:"mypassword1"
};
mongoose.connect(url,options,callback);
The user with username and mypassword was created in the firstdb itself giving it readWrite perms. I did this while logged in with my admin user.
Things were working smoothly. Then I had a requirement of connecting to a second database. So I changed my code as such
let url1 = "mongodb://localhost:27017/firstdb";
let options1 = {
server:{
socketOptions:{
keepAlive:120
}
},
user:"username1",
pass:"mypassword1",
auth:{
authdb:"firstdb"
}
};
let connection1 = mongoose.createConnection(url1,options1);
let url2 = "mongodb://localhost:27017/seconddb";
let options2 = {
server:{
socketOptions:{
keepAlive:120
}
},
user:"username2",
pass:"mypassword2",
auth:{
authdb:"seconddb"
}
};
let connection2 = mongoose.createConnection(url2,options2);
This time I created user username2 the same way in the seconddb database. But now mongoose is unable to perform any operation and is failing with Not authorized to execute command. I can access the db through mongo shell though. I also spun up the code in my local system which doesn't have mongodb auth enabled and it works fine there. Please help
So, after shooting around in the blind, found something that works.
Use the username and password in the url itself like
let connection1 = mongoose.createConnection("mongodb://username1:password1#localhost:27017/firstdb");
Still, I would like to know why passing the parameters as options doesn't work.

'Execute failed:unauthorized' when using RockMongo with MongoLab

I can't use RockMongo(v1.1.2) to connect MongoLab, what did i do wrong?
In my MDb.php file
$MONGO["servers"][$i]["mongo_name"] = "MongoLab";
$MONGO["servers"][$i]["mongo_host"] = "ds053xx.mongolab.com";
$MONGO["servers"][$i]["mongo_port"] = "53818";
$MONGO["servers"][$i]["mongo_timeout"] = 0;
$MONGO["servers"][$i]["mongo_auth"] = true;
and when I log in with my username, password, db_name
It can log in but I can't do anything with it
on the left side of the screen it show
Execute failed:unauthorized
function (){ return db.getCollectionNames(); }
I have no problem when connect to local database.
And also can use the same url,port,username,etc. with MongoVUE
This doesn't appear to be anything you're doing wrong. It looks like RockMongo requires admin access because it's trying to list collections for databases other than your own (such as the admin and local databases), which is not possible w/ MongoLab's Sandbox databases.
https://github.com/iwind/rockmongo/issues/35
If you want to access only your own database, you can change the following line 31 inside rockmongo/apps/models/MDb.php listCollections(MongoDB $db) function:
from
$names = self::exec($db, 'function () {
return db.getCollectionNames();
}');
to
$names = $db->getCollectionNames();

Node.js mongodb-native driver authentication in cloudfoundry

I'm currently trying to mess around with Node and Mongo for a bit of self learning. Ive been looking at various blog entries and have been messing with getting a simple blog written in node with a mongo db working.
Anyway I'm having trouble making it work in cloudfoundry. I've looked on the mongodb-native usergroup about authentication and found some node script:
var Db = require('mongodb').Db;
var Connection = require('mongodb').Connection;
var Server = require('mongodb').Server;
var BSON = require('mongodb').BSON;
var ObjectID = require('mongodb').ObjectID;
ArticleProvider = function(dbname,host, port,username,password) {
this.db= new Db(dbname, new Server(host, port, {auto_reconnect: true}, {}));
this.db.open(function(){
this.db.authenticate(username, password, function(err, db) {
callback(err, db);
});
});
};
I can't for the life of me get this working.
this.db.authenticate(username, password, function() {});
^
TypeError: Cannot call method 'authenticate' of undefined
at /home/ben/NodeJS/sandbox/NodeBlog/articleprovider-mongodb.js:10:17
at /home/ben/NodeJS/sandbox/NodeBlog/node_modules/mongodb/lib/mongodb/db.js:81:14
at /home/ben/NodeJS/sandbox/NodeBlog/node_modules/mongodb/lib/mongodb/connections/server.js:76:11
at /home/ben/NodeJS/sandbox/NodeBlog/node_modules/mongodb/lib/mongodb/admin.js:16:12
at [object Object].<anonymous> (/home/ben/NodeJS/sandbox/NodeBlog/node_modules/mongodb/lib/mongodb/admin.js:124:12)
at [object Object].emit (events.js:67:17)
at [object Object].<anonymous> (/home/ben/NodeJS/sandbox/NodeBlog/node_modules/mongodb/lib/mongodb/connections/server.js:97:12)
at [object Object].emit (events.js:64:17)
at Socket.<anonymous> (/home/ben/NodeJS/sandbox/NodeBlog/node_modules/mongodb/lib/mongodb/connection.js:108:16)
at Socket.emit (events.js:64:17)
Anyone able to point out where I'm being a complete facepalmer would be much appreciated.
I have also faced same kind of problem. Trying harder I have found the solutions.
This may be very helpful to all the mongodb developers.
var ArticleProvider = function(host, port, username, password) {
this.db= new Db('my_db', new Server(host, port, {auto_reconnect: true}, {}));
this.db.open(function(err,data){
if(data){
data.authenticate(username, password,function(err2,data2){
if(data2){
console.log("Database opened");
}
else{
console.log(err2);
}
});
}
else{
console.log(err);
}
});
};
Cheers..
The easiest way connect this is to use a mongourl (mongodb://localhost:27017/db...) and the connect function in the node-mongodb-native drivers.
Cloudfoundry starts a very specific authenticated database and then tells you about connecting to that database within the environment variables, which can make it tougher to debug. Ideally you want it to work on both your local machine and on Cloudfoundry in basically the same way.
Fortunately, I posted an article on MongoDB.org that walks you through a simple Cloudfoundry setup. It has step-by-step instructions from zero to up and running both locally and on Cloudfoundry.
Plus there's a github code sample.