createConnection MongoError: Authentication failed - node.js

I have a node.js app that uses MongoDB as a database.
I have also the management of MongoDB.
When the app starts, it connects to MongoDB without any problem.
I am trying to let the user defines which database he/she will connect to. To do that I create mongo.conf like that:
And in the app, I defined the connection uri like that:
MONGODB_URL="mongodb://< username>:< password>#34.72.5.46:27017/"
The database user has the root role. As I mentioned, in first opening the app connects to the database. In the first opening, I am using mongoose.connect
But when the user inserts a database name that doesn't exist, via the app, I am using mongoose.createConnection. And then I get this error:
MongoNetworkError: failed to connect to server [34.72.5.46:27017] on first connect [MongoError: Authentication failed.
What should I do?

I solved my issue. It has been needed to add "?authSource=admin" at the end of the mongo URI

Related

Can i use a single user to connect different databases in MongoDB?

I hava tried to create a user in database "admin" with roles of "root","readWriteManyDatabase" in mongodb to connect to different databases, but it seems that i can not use
this user to directly connect to the other databases, but i can do operations on other databases after run db.auth() in database admin.
So, is there any way i can use to connect directly to different databases with a same user but do not need to first connect to database "admin"
Make sure you're authentication with the admin database when connecting to the database server, this can be specified on the MongoDB Connection string by passing a query string parameter of authSource. For example:
mongodb://username:password#my-server/my-db?&authSource=admin
If you don't specify an auth source then it will try to authenticate using the database specified, in this case my-db
If you're using the shell you can specify this as an arugment of authenticationDatabase for example:
mongo localhost -u user -p password --authenticationDatabase admin

Using Twitter for user authentication in Heroku: "can’t establish a connection to the server at 127.0.0.1:8080"

I am following this scotch.io tutorial on twitter node authentication to authenticate users on a Heroku app. I have made my callback URL this: http://127.0.0.1:8080/auth/twitter/callback
I am able to click on a link to authenticate the user but then and it says "can’t establish a connection to the server at 127.0.0.1:8080"
No useful clues in the logs. I believe I have set up all my routes and .js files properly, as laid out in the tutorial, and am not sure what could be causing this problem.

Facebook login in parse after migration

I completed all the steps of migrating from parse to my local server windows server 2012R2 deployed mongoDB and the parse server and the node.js and python on the server and of course installed the webserver role on the window.
I am now successfully listening to port 1337 for connections and I connected my node.js to the mongoDB and also accepted connections successfully to the database via port 27017. Entered my new app keys and client keys and updated them on my application. But my application has facebook login. And for sure when I open the app to login it gives me an error in the console saying "facebook auth is not configured". Ordinary user login is working but the Facebook one is not.
I think there was a way that I can add my facebook app ID to the nodejs index file where I updated all the keys. But I really don't know how to do it. If any body has experience in deploying parse on his own web server please advise.
Thanks.

How to connect chrome extension with mongolab

I have a chrome extension i have made a sign up page and now i want to connect it with mongolab and store the data into the mongolab collection . Basically i want to make connection of a chrome extension with mongolab.
Got solution here on this web page : http://etoxin.net/blog/2013/07/09/mongodb-and-jquery-in-10-minutes/
Here they have used api of making a connection with mongolab using the api key of that collection created.

Creating database dynamically using nodejs in an authenticated environment of mongodb

Started mongod shared instance without keyfile option
Created a user in admin database with all roles and then started the instances with the keyfile option
Using that user we saved a serverside scripting to create a database dynamically.
Then from nodejs we connected admin db and tried executing the serverside script using db.eval
getting the below mentioened error
/home/administrator/Node# node t1.js
open!
Error :null
Error :Error: eval failed: unauthorized

Resources