Datanucleus Mongodb with authentication - mongodb

I am using datanucleus for JPA on Heroku with mongodb (mongolabs). Even when I set these properties:
datanucleus.ConnectionPassword=YYYYY
datanucleus.ConnectionUserName=XXXXX
I get PersistenceException: Authentication of the connection failed for datastore heroku_app2765673 with user XXXXXXX
Does datanucleus support connecting to mongodb with a password? It seems to know my username, so I assume so. What am I doing wrong?

Removing and readding my mongolabs account seems to have fixed this. Don't know what the actual problem was, but it clearly wasn't datanucleus.

Related

Connecting to MongoDB database on mLab fails authentication

I have a Parse app, and I'm trying to migrate my app's database to a MongoDB instance on mLab.
I already have a fork of Parse Server set up on Heroku, and I'm using Heroku's mLab MongoDB add-on.
I have a database on mLab called heroku_1ksph3jj, and I should be able to connect to it with the following template:
mongodb://<dbuser>:<dbpassword>#ds047124.mlab.com:47124/heroku_1ksph3jj
However, each attempt returns:
Server returned error on SASL authentication step: Authentication failed.
I'm unsure what to replace <dbuser> and <dbpassword> with. I have a database user with the same name as my database: heroku_1ksph3jjz, so I used that. And I used the password for that user in place of <dbpassword>. Should I have used something else here?
You can get the dbuser and dbpass with:
heroku config | grep MONGODB_URI
Grab the dbuser (example_user) and dbpass (example_pass) from the response:
MONGOLAB_URI: mongodb://example_user:example_pass#mlab.com:12345/db
As of March 2016, mLab.com only supports mongo 3.0+ (as per a conversation with support), because of their new onerous authentication requirements.
This was not on the website, but I hope it helps someone here!
There's a message to create a user for the specific database:
A database user is required to connect to this database. To create one now, visit the 'Users' tab and click the 'Add database user' button
I'm so sorry that this may seem obvious but, you have to remove this characters <> for the migration to work
In your example would look like this:
mongodb://dbuser:dbpassword#ds047124.mlab.com:47124/heroku_1ksph3jj
Check your mongo client version. If it is in older major version (probably 2.x), update it to 3.x
For future visitors - don't use special characters in password .Even if you change the special character to ascii or unicode it wont work for mLab using mongoose.
Also don't use mLab credential , use db user credentials . I created a new user.
Eg. For me a password containing # character was replaced with ascii value %40 in URI , which worked when using native mongodb driver.
But on using mongoose, i was always getting Authentication Failed .
I removed special characters and db was authenticated via mongoose.
It looks like it was the password that was incorrect, which I'm assuming was set up by Heroku's mLab add-on. There was no obvious way to reset this in the mLab UI, so in the end I created another database user (with a new username and password) and was able to connect with that just fine.
Just go to your Heroku dashboard and check your settings.
Under the name field there's a big button "Reveal Config Vars". Click it and you'll see a MONGODB_URI var with a uri to your db. It'll look something like this:
mongodb://heroku_user:PASSWORDyourLOOKINGfor#ds2238985.mlab.com:63295/heroku_user
Your password is right after the semicolon after the heroku user name.
I know I am too late, just for information.
For getting the info of mLab account that got auto created when mLab addon got added to the application in your heroku account, try the below command.
heroku config:get MONGODB_URI
Ref:
http://algebra.sci.csueastbay.edu/~grewe/CS6320/Mat/NodeJS/Heroku/Heroku_MLabMongoDB.html

Mongo::Error::OperationFailure (not authorized on [db] to execute command....(13))

On my production server, I keep getting not authorized error randomly. The following is my setup:
MongoDB 3.2.1
Mongo (ruby driver) 2.2.3
Mongoid 5.1.1
bson 4.0.2
I don't have username and password configured in mongoid.yml. I only have uri configured to connect to remote database server.
I search-fu was weak, and couldn't find anything that could explain/help what's going on.
Any help would be much, much appreciated.
Thank you,
It seems like upgrading to mongo 3.x fixes the problem, as this jira ticket shows.
https://jira.mongodb.org/browse/RUBY-1100

Error trying to connect to mongolab from cdm: Error: 18 authentication fail

I'm getting this error when I try to connect to my mongolab DB.
I saw some different topics talking about this issue, but solutions they gave was:
-Add mongoDB exception in my firewall. I done it without result
-Check if I was using the mongolab.com user and password instead of the user database. That's not the problem, even I created new users.
-Check if my version of mongoDB was older than the version used by mongolab (3.x). I also specified the auth system in the command to be sure.
I tried all those answers without success. I also checked the connection with the server, and it neither was the problem. I'm going crazy.
What could be the issue?
Thanks for your attention!
It was finally a network problem. I was lucky to discover it, cause I lost many hours.

Dart - error when trying to authenticate with mongodb

After running:
import 'package:mongo_dart/mongo_dart.dart';
//Create account with given credentials
createAccount(Map<String, String> credentials) async {
Db db = new Db('mongodb://127.0.0.1/exampledb');
await db.open();
await db.authenticate("user", "password");
//TODO: Post credentials into DB
}
I get an error on the Dart server saying:
Unhandled exception:
Uncaught Error: {ok: 0.0, errmsg: auth failed, code: 18}
And a different error comes up up on the mongod server:
2015-09-27T20:04:25.921+0100 I ACCESS [conn1] Failed to authenticate user#exampledb with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentia
ls missing in the user document
The only time when the authentication has succeeded and has allowed me access to the database is when I am using the command prompt.
Example:
$ use exampledb
$ db.auth("user", "password")
How can I make my Dart script gain access to my local mongodb, using the authenticate method?
Fresh update:
Since version 0.2.5 mongo_dart supports SCRAM-SHA-1 authentification mechanism. It used by default in connections to MongoDb 3
Update:
That seems to be rather widespread problem with some drivers, programs e.t.c not supporting yet new authentication mechanism (SCRAM-SHA-1) of mongodb 3.0
By default, mongodb 3.0, do not create credentials in old format (MONGODB-CR) while creating new users.
There is round-about solution, that force mongodb 3.0 and upper version use MONGODB-CR mode while creating users.
Look for example solution at https://jira.mongodb.org/browse/SERVER-17459
As stated in that thread
both new drivers and legacy software work with that solution
Obviously best solution for mongo_dart would be to add implementation of new authentication mode to the driver. Can not give any date, but I think it should be first feature that I can take in consideration as soon as I have some time for mongo_dart.
And obviously it would be great if somebody beat me at that with pull request :)
Original answer
I've reproduced that error in my environment too.
Error appears to be related to changed default authentication mode in version 3.0 of MongoDb. I'll update this answer, when the problem will be resolved
I tried that in my mongodb 4.0.10 and mongo_dart 0.3.6 and the authentication went all right and correct just update your components if you didn't yet and everything will be fine.
PS: I know I am late but hope someone get used from my "Note".

Heroku could not authenticate mongolab

It was corrected two days ago. And yesterday I committed some changes to heroku and the application crashed, I found from heroku logs that:
/app/.bundle/gems/ruby/1.9.1/gems/mongo-1.4.0/lib/mongo/db.rb:137:in `issue_authentication': Failed to authenticate user 'larryzhao' on db 'uthenera' (Mongo::AuthenticationError)
I even explicitly input the host/port/username/password/db name into mongoid.yml, still it could not get pass authentication.
I tried both database in Rackspace and in Amazon, but neither could authenticate.
Have you met with that before? Is there anything else I could check on Heroku besides heroku logs ?
Thanks.
Today I encountered the same on Heroku:
Mongo::AuthenticationError: Failed to authenticate user 'heroku_app111' on db 'heroku_app111'.
from /home/ad/.rvm/gems/ruby-2.1.3#app/gems/mongo-1.11.1/lib/mongo/functional/authentication.rb:205:in `issue_authentication'
It's not because of this RUBY-890 bug, but because MongoLab upgraded to MongoDB 3.0 which uses SCRAM-SHA-1 challenge-response user authentication mechanism. So I needed latest ruby mongo driver version which is counting with this. In my case latest 1.x branch.
The minimum driver versions that support SCRAM-SHA-1 are:
Driver Language Version
C 1.1.0
C++ 1.0.0
C# 1.10
Java 2.13
Node.js 1.4.29
Perl 0.708.0.0
PHP 1.6
Python 2.8
Motor 0.4
Ruby 1.12
Scala 2.8.0
Of course you have to be sure your credentils are ok :)
Make sure you're using the right username to connect to your database. The username you use to log into mongolab.com is different from the one attached to the 'uthenera' database. Have a look at the Users tab for that database at mongolab.com to see what database user(s) you've configured.
Hope that helps. Feel free to email support#mongolab.com if you need further assistance.
-Robert
You can get your database username and password using:
heroku config | grep MONGODB_URI
The response is in this format:
MONGOLAB_URI: mongodb://username:password#mlab.com:12345/db