MongoDB and Robomongo: Can't connect (authentication) - mongodb

I have the following user:
{
"_id" : "admin.root",
"user" : "root",
"db" : "admin",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
}
And for my database:
{
"_id" : "mydb.mydbDbOwner",
"user" : "mydbDbOwner",
"db" : "mydb",
"roles" : [
{
"role" : "dbOwner",
"db" : "mydb"
}
]
}
I can't connect via Robomongo on localhost:
The same goes for...
Database: mydb
User Name: root
Database: mydb
User Name: mydbDbOwner
How can I fix this problem?

Robomongo 0.8.x doesn't have support for the new SCRAM-SHA-1 authentication which was the default authentication method added in MongoDB 3.0.
Robomongo 0.9.0 RC4 (Feb 2016) added support for SCRAM-SHA-1, but if you are using a modern version of MongoDB server you should upgrade to the latest version of Robomongo (now Robo3T) currently available.
There is also an officially maintained free GUI, MongoDB Compass, which is more actively updated than Robo3T. MongoDB Compass 1.22+ (Sept 2020) includes an embedded MongoDB shell.

I was experiencing exactly the same issue on Mac. I removed the Robomongo client and download the latest version from their website. It just works :)

You can change localhost to 127.0.0.1

You can try Mongo-Express (a web-based tool).
However, you need to upgrade the MongoDB-Node.js library to be at least (1.4.29) according to Upgrade to SCRAM.
I tried and it worked for my case. You can find the below useful command for that:
npm install mongo-express
cd node-modules/mongo-express
Change the config.default.js file to config.js and update it to include your database connection (e.g., username, password, connection's URL, etc.)
Edit the package.jon file and change the version of MongoDB to "~1.4.29"
Run: npm update
To start the web application: execute command "node app" and the web site will be available at http://localhost:8081/.

I just upgraded to the new version 1.0 of Robomongo. As a few people stated in here, 0.8.x didn’t support SCRAM-SHA-1, which is default in MongoDB 3.0. In prior versions it was MONGODB-CR.
But anyone who is downloading Robomongo from this point on shouldn't have an issue with authentication.
https://robomongo.org/
This bottom links explains SCRAM-SHA a bit more. I suggest reading into it if heavily using MongoDB.
SCRAM

Possibility for connection through an SSH tunnel with Robomongo is back in the RC8 version. See GitHub issue Where is the SSH tunnel settings on v 0.9.0 RC2 Mac version #1008.

Related

How to connect vapor to mongodb atlas

So I have a vapor \ fluent app that works fine with local mongo instance, here's current mongo.json:
{
"database" : "vapor",
"port" : "27017",
"host" : "127.0.0.1",
"user" : "",
"password" : ""
}
I've deployed a free MongoDB Atlas 3 replica set and I wonder how do I connect the app to it?
Fluent's MongoDB integration is using an outdated version of MongoKitten. Currently we're at MongoKitten 4. MongoKitten 1, which is being used in Fluent currently supports just a fraction of the features with a much worse performance.
Check that your mongod instance is listening on the necessary network interfaces
Check that your firewall is open and you can connect to the mongod process from your application node
Check that your mongod is secure, i.e. you can connect only with known credentials
In the application's mongo.json:
"host": "replica_set_name/first_RS_node_address, second_RS_node_address, third_RS_node_address",
"user": "your_user_name",
"password": "wery_secret"

mongoDB Atlas ♥︎ Sailsjs (waterline sails-mongo adapter)

i just created a MongoDB Atlas account.
I'm using sails with waterline sails-mongo adapter
but I can't manage to connect via my app.
Everything is up to date.
I can connect to any other DB (localhost, digitalocean server, ...)
I can also connect to that MongoDB Atlas Database via their tool (MongoDB Compass) and via shell with the mongo cmd
but it seems like sails-mongo is just not working with that db, which requires a very up-to-date mongo version
Is someone else using MDB Atlas && sailsjs ?
(I thought about refactoring my app, but it's starting to be huuge and it just seems impossible to use the "mongodb" adapter)
Versions :
- node : 6.3.1
- npm : 3.10.6
- mongo (shell) : 3.4.2
- sails-mongo npm module : sails-mongo#0.12.2
Hey people thanks to your tips and SailsJS team I was able to figure out a few things that can help you fix this issue (I was able to):
Update your sails-mongo to v0.12.3 npm install sails-mongo#0.12.3 --save
Update sails-mongo's mongodb dependency to v2.2.25. You can do this editing package.json. That version includes a fix for replicaSets connections: https://github.com/mongodb/node-mongodb-native/commit/915d5c8a765151fb14942445a92d92a0e9e9c942#diff-88dc7475eedf918122374be6d7c2c151R12
Make sure that the mongodb's mongodb-core version is at least v2.1.9.
Now I went directly and created my connection like this:
{
adapter: 'sails-mongo',
url: 'mongodb://user:pass#server-1.mongodb.net:27017,server-2.mongodb.net:27017,server-3.mongodb.net:27017/test?ssl=true&replicaSet=server-&authSource=admin',
ssl: true
}
Yes, you need to add the ssl parameter again.
By looking at the sails v1.0 code, lost of this things will be fixed by that update ;) Thanks SailsJS Team!
it seems like sails-mongo is just not working with that db, which requires a very up-to-date mongo version
You hit the nail on the head -- the current sails-mongo adapter for Sails v0.12.x uses a version of the native MongoDB driver that doesn't support all the features required to work with Atlas (e.g. authSource). See this issue on Github.
We're finishing up the last bits on the sails-mongo adapter for Sails 1.0, which supports the latest options and has been tested successfully with Atlas, so now might be a good time to start preparing to upgrade to version 1.0. After Sails 1.0 is released we'll only be doing bug fixes and security patches to modules that work with v0.12.x.
The error message suggests that the connection is timing out. Step one would be to check your configuration, is it correctly populated with this format in config/connections.js?
// MongoDB is the leading NoSQL database.
// http://en.wikipedia.org/wiki/MongoDB
//
// Run:
// npm install sails-mongo
//
someMongodbServer: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
// user: 'username',
// password: 'password',
// database: 'your_mongo_db_name_here'
},
If it's not your configuration, it's likely an incompatibility with your version of sails, sails-mongo, or Mongo DB. Which versions of these are you running?

MongoDB error: Cannot use 'commands' readMode, degrading to 'legacy' mode

So I was developing a project using mongo and I got an error after executing the code:
db.usercollection.insert({ "username" : "testuser1", "email" : "testuser1#testdomain.com" })
The error displayed was:
Cannot use 'commands' readMode, degrading to 'legacy' mode WriteResult({
"writeError" : {
"code" : 13,
"errmsg" : "not authorized on watersheds to execute command { insert: \"usercollection\", documents: [ { _id: ObjectId('568d0eda45d472b121116bef'), username: \"testuser1\", email: \"testuser1#testdomain.com\" } ], ordered: true }"
} })
The db.version() is 3.0.7 and I installed MongoDB shell version is 3.2.0
How should I fix this?
Regards,
Daryll
db.getCollection(collectionName).count({});
db.getCollection(collectionName).find({});
It works! maybe mongo needs other operation.
I just restart the mongod process instead and works for me.
Expanding on #Buzut's comment above...
I just ran into this same error. For me, the issue was a version difference between the client running locally and the version of the mongo db running in the cloud.
To verify if that's your issue, run mongo --version locally and take note of the version number. Then connect to your mongo db shell and run db.version() to check the version there.
If there is a major difference in those numbers (like a version 3 client and a version 2 db), you'll likely need to switch to client version that's closer to your db version.
To do that, go the Mongo download center: https://www.mongodb.com/download-center#production
Select your platform, then click on 'All Version Binaries', and look for a download that matches your hosted db.
That will download a compressed file that you'll need to unpack. And inside there will be a folder. Simply use the path to the /bin/mongo executable (inside that folder) to execute your mongo commands. For example:
/path/to/downloads/mongodb-osx-x86_64-2.6.9/bin/mongo <whatever mongo commands you want>
Hope that helps.
I don't know if you are a victim of having replica set and lost Primary db or not.
If so, recreate the Primary one or use this command before your insertion.
db.getMongo().setSlaveOk();
Cannot use 'commands' readMode, degrading to legacy mode,
rs-ds017231:PRIMARY> show dbs
rs-ds017231:PRIMARY> db
rs-ds017231:PRIMARY>db.collection_name.insert({})
It works for me !

MongoDB-CR Authentication failed

I am getting following error while authenticating user : purchase_user#purchase failed. MongoDB-CR Authentication failed. Missing credentials in user document when I access webservice through browser.
But I am able to authenticate purchase_user from mongo it returns 1 .
go to mongoDB console and delete your current user & set authSchema version to 3 instead of 5 , follow these commands in mongo console -
mongo
use admin
db.system.users.remove({}) <== removing all users
db.system.version.remove({}) <== removing current version
db.system.version.insert({ "_id" : "authSchema", "currentVersion" : 3 })
Now restart the mongod and create new user then it should work fine.
Note: use remove commands in test db only, if in production use update.
Authentication information for Kubernetes Helm Chart
If you delete the all users and authentication is enabled in the configuration (or --auth param which is set per default on the Kubernetes helm chart), it's not possible to access MongoDB any more. Its required to disable authentication, create a new user and then re-enable it.
On Kubernetes you need to edit the parameters and add --noauth as argument, since it's not the default there as on a classic installed MongoDB. Please see the CLI documentation for more information about --noauth and the corresponding --auth.
Had the same issue. What was happening to me was that when I use MongoDB 3 to create my user, it was using SCRAM-SHA-1 as it's authentication mechanism instead of MongoDB-CR. What I had to do was:
List item
Delete the created user.
Modify the collection admin.system.version such that the authSchema's currentVersion is 3 instead of 5 (3 is using MongoDB-CR).
Recreate your user.
Should work without problems now.
The step number 2. above is not detailed explicitly, I found this solution and worked for me.
var schema = db.system.version.findOne({"_id" : "authSchema"})
schema.currentVersion = 3
db.system.version.save(schema)
I think this is the answer you need:
1) Start 3.0 without auth enabled. (Auth needs to be disabled otherwise you'll get the not authorized error).
2) Run (after selecting "admin"use db):
var schema = db.system.version.findOne({"_id" : "authSchema"})
schema.currentVersion = 3
db.system.version.save(schema)
3) restart mongodb with auth enabled.
4) Create a new admin user (the old one, the one you created before this workaround won't work).
Things should work now. This issue was driving me crazy as well.
Answer came from here: https://jira.mongodb.org/browse/SERVER-17459
Adding to above solution by Vivek & explanation taken from here
use admin
db.system.users.remove({}) <== removing all users
db.system.version.remove({}) <== removing current version
db.system.version.insert({ "_id" : "authSchema", "currentVersion" : 3 })
you only need to downgrade the schema to create MONGODB-CR users.
Once they are there the old drivers will work regardless of the value
of authSchemaVersion. However if you run authSchemaUpgrade to change
from "3" to "5" the users will obviously be upgraded.
My comment regarding new users was that if you have existing SCRAM
users and change the schema manually to "3" the user documents won't
be consistent with the new schema. This is not enforced however but
the SCRAM users will still work for any driver supporting SCRAM.
Upgrade mongo-java-driver to 3.0.3 and use :-
MongoCredential.createScramSha1Credential instead of MongoCredential.createMongoCRCredential
MongoCredential createMongoCRCredential = MongoCredential.createScramSha1Credential(mongoConfiguration.getDatabaseUserName(), mongoConfiguration.getAuthenticationDatabase(),mongoConfiguration.getDatabasePassword().toCharArray());
http://docs.mongodb.org/master/release-notes/3.0-scram/
For me I was using a mongo 2 client trying to connect to a mongo 3 server. Upgrading the client fixed the issue.
I was getting this error as well.
Check your Spring Config file.. I had a constructor arg named "MONGODB-CR" which I swapped to "SCRAM-SHA-1" and it fixed my issue.
tailing the mongodb log file helped me diagnose this.
uninstall mongodb-clients packages provided by Ubuntu
install mongodb-org-shell provided by official MongoDB
This solved the problem, because The unofficial mongodb package provided by Ubuntu is not maintained by MongoDB. You should always use the official MongoDB mongodb-org packages, which are kept up-to-date with the most recent major and minor MongoDB releases.
Probably old news, and problem solved, but adding my experience with the same error:
I had the exact same problem (using MongoDB 3.0), and a C# driver that was setup to use a pre 3.0 db.
In C# I used "MongoDB.Driver.CreateMongoCRCredentials()", which caused the error the OP was getting.
The fix (for me), was to switch the command above to "MongoDB.Driver.CreateCredential()".
I guess this could be caused by using "old" users (from pre 3.0) on an upgraded system. Which either forces you to upgrade your users to the new authentication mechanism, or downgrade the authentication mechanism on your server.
June 2018 I got this error after trying to connect to my Mongodb version 3.6 from an ancient client installed in /usr/bin. I installed the mongo DB in a separate folder outside of the OS standard directory, and so my installation was conflicting with the ancient version installed by the package manager.
For those who is struggling to update auth schema (see the accepted answer) in MongoDB 3.6 due to the not authorized on admin to execute command and removing FeatureCompatibilityVersion document is not allowed errors, this is what's worked for me.
To resolve the first error:
> db.system.version.remove({})
WriteResult({
"writeError" : {
"code" : 13,
"errmsg" : "not authorized on admin to execute command { update: \"system.version\", ordered: true, lsid: { id: UUID(\"58e86006-d889-440a-bd83-ad09fcd81747\") }, $db: \"admin\" }"
}
})
I had to create a custom role that permits any action on any resource and a user with this role, then login to the admin database with that new user:
mongo admin
db.createUser({user: 'admin', pwd: 'mypwd', roles: ['root']})
exit
mongo admin -u admin -p
db.createRole({role: 'fullaccess', privileges: [{resource: {anyResource: true}, actions: ["anyAction"]}], roles: []})
db.createUser({user: 'superadmin', pwd: 'mypwd', roles: ['fullaccess']})
exit
mongo admin -u superadmin -p
(Just using the admin user with root role or disabling security.authorization in config didn't work for me and still had the same error when trying to update the system.version table.)
After that I had another error:
> db.system.version.remove({})
WriteResult({
"nRemoved" : 0,
"writeError" : {
"code" : 40670,
"errmsg" : "removing FeatureCompatibilityVersion document is not allowed"
}
})
To resolve it, we should only update the authSchema document instead of removing the whole collection.
(Generally speaking, you shouldn't blindly remove everything from system tables in production and always check what would be the implications of updating them, so that's another reason to update the needed record only.)
db.system.version.update({"_id": "authSchema"}, {currentVersion: 3})
Now you should be able to create a user with the old authentication mechanism. You also might need to switch to your database first, so that the user is created in that database rather than in admin one. Otherwise you'd have to use the authSource=admin parameter in your connection string.
(I'm actually lying here - it still will be created in admin database, just with mydb.myuser id instead of admin.myuser. But I use the same way of describing these things that's being used in MongoDB documentation. I suppose this is how it actually used to work in previous versions and in general we shouldn't care about the internal implementation details.)
use mydb
db.createUser({user: 'myuser', pwd: 'mypwd', roles: [{role: 'dbOwner', db: 'mydb'}]})
And don't forget to cleanup:
use admin
db.system.version.update({"_id": "authSchema"}, {currentVersion: 5})
exit
mongo admin -u admin -p
db.dropUser('superadmin')
db.dropRole('fullaccess')
You may want to keep the admin user - I was not able to create it again even with security.authorization setting disabled. It looks like if there are any records in admin.system.users table, the setting does not work anymore and mongo requires authentication to do something.
I had the same error with a Spring Boot app using a new MongoDB 3.2.8 database. By upgrading to the latest version of the Java Mongo driver (3.2.2) and then adding the authentication mechanism param to the URI in my application.properties, I was able to get it working:
spring.data.mongodb.uri=mongodb://myusername:mypassword#localhost/?authSource=admin&authMechanism=SCRAM-SHA-1
spring.data.mongodb.database=test

MongoDB Sensu Script(Check) not showing Metrics in Log

I have sensu client installed on Mongo DB server and I am executing the Mongo DB Check using this script It Works great when my Mongodb is configured without Authentication, But it does not show the metrics when Authentication is enabled on the Mongo DB, Though I am passing the DB Authentication Credentials correctly, but authentication works with same credential from irb prompt. What should be the fix to get the Monitoring Metric using MongoDB Authentication ?
I am using Sensu version 0.1 6 and MongoDB 2.4.11 on Ubuntu 12.04.
I resolved it,
In fact it is not an sensu-plugin issue, it was an user authentication issue with MongoDB 2.4, Mongo allows the user which is created within admin db to collect the information of other databases.
So the following simple steps solved my issue
rahul#rahul:~$ mongo
MongoDB shell version: 2.4.12
connecting to: test
> use admin
switched to db admin
> db.addUser("rahul","rahul#123")
{
"user" : "rahul",
"readOnly" : false,
"pwd" : "85a20670734aeb830a7903183bd4132f",
"_id" : ObjectId("54d88f4950e99f42d01abfe8")
}
> use mydb
switched to db mydb
>
Then I modified following paramaters in mongodb-metrics.rb which is freely available here
option :user,
description: 'MongoDB user',
long: '--user rahul',
default: nil
option :password,
description: 'MongoDB password',
long: '--password rahul#123',
default: nil
and note that the following has to be unchanged
db_name = 'admin'
here I was giving db_name as 'mydb' which was going wrong
after all I can see my metrics and graphs