Problems in executing a query in mongodb - mongodb

I have this exception being thrown with mongodb connection
Wed May 11 10:39:33 Assertion: 10057:unauthorized for db [inbox] lock type: -1
where inbox is the database. I am using the PHP driver for the connection. The problem is I am using the admin username and password for the connection but still it is throwing unauthorized. Can you please provide some insights.

Authenticating as an admin requires you to run the authenticate command in the admin database before changing to the regular database. Authenticating your admin user from say, test will not work.
For your case, connect to admin, run authenticate as the admin user, and then get a handle on inbox. Alternately you should create a user specific to the inbox database for safety. Connecting as a superuser for an application isn't the best idea.

Related

mongo dump and restore (when restoring in different os)

I am working on a project, there I need to dump a database from windows and need to restore it on a centos server.
Whenever I do that, there is some error.
Like - error reading database: (Unauthorized) not authorized on mydatabase to execute command
or
error connecting to host: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
Both os have the same mongo version that is 4.2
How can I correct it?
The error not authorized on mydatabase to execute command indicates that either you have not authenticated, or the authenticated user has not been granted the appropriate permissions to execute that command.
Authentication failed means just that. The server side log may have more detail, like the user and database names used in the auth attempt.
To fix these, make sure:
you are providing authentication credentials
the user account you are using has already been created in the server
the user account has been granted permission for that command on the correct database/collection
The Security page in the docs might be a good place to start.

Error 13 when trying to authenticate to MongoDB

I'm trying to connect to MongoDB through JDBC. The connection string is like below,
mongodb://localhost:27017/games?authSource=admin
However I'm getting the following trace:
{ "ok" : 0.0, "errmsg" : "not authorized on admin to execute command { listDatabases: 1 }", "code" : 13 }
My intention is not listing all the databases, but the user has to authenticate against admin database and can read/write on games database. What mistake I'm making here?
I want user X to authenticate against admin DB but read just games DB so not sure why it asks for listDatabase privilege.
First, I assume you are using the MongoDB Java Driver, which is actually not JDBC.
It would be helpful for you to share:
How you created your user
The Java code that you are executing
The version of mongo-java-driver and MongoDB that you are using
But based on the error, it appears that you are successfully authenticating. I strongly suspect that you are either directly calling listDatabases() or listDatabaseNames().
The other thing that does not look quite right is the fact that you are specifying authSource=admin in your MongoClientURI. But that issue should have given you an Autentication Failed error. You should be either leaving the authSource off of the connection string or specify authSource=games.
Based on what you described, when you created your user, you should have created the user in the games database (users will actually be stored in the admin database, but you would be authenticating against the games database).

MongoDB 3.2 - Admin user not authorized to execute command

I have created an admin level user and given the dbAdminAnyDatabase, userAdminAnyDatabase, readWriteAnyDatabase permissions on the admin database as well as my other database and I can create a successful connection to the client but when I try to run a command to retreive data I get an error saying 'Command find failed: not authorized on {database} to execute command'.
Any ideas on why this isn't working?
I found an example where the user was made to have "root" access and now I can successfully query data. The question still remains why the above credentials didn't work.

Failed to connect MongoDB 3.X with MongoVUE

I am running MongoDB on windows8.1 and created users for admin database. For convenience, I use mongoVUE to check data. But after turning on the "auth" function. I cannot logged in.
Actually, I can use the username and password to authenticate with mongo shell. Further more, I can also use them to authenticate by python codes. They failed to work only when I use mongoVUE or Robomongo.
When I clicked "test" button on mongoVUE, it returned a message "Connection was refused". And the windows command shell presents the following words:
2015-07-03T19:52:34.843+0800 I NETWORK [initandlisten] connection
accepted from
127.0.0.1:24163 #242 (4 connections now open)
2015-07-03T19:52:34.845+0800 I ACCESS [conn242] authenticate db:
admin { auth enticate: 1, user: "uvpaiad", nonce: "xxx", key: "xxx" }
2015-07-03T19:52:34.846+0800 I ACCESS [conn242] Failed to
authenticate uvpaiad #admin with mechanism MONGODB-CR:
AuthenticationFailed MONGODB-CR credentials mi ssing in the user
document
2015-07-03T19:52:34.847+0800 I NETWORK [conn242] end connection
127.0.0.1:24163 (3 connections now open)
Does anyone know what the matter is?
This is because of the changed authentication mechanism in MongoDB latest version. In Mongo 3.X, auth mechanism is changed to SCRAM- Salted challenge response authentication mechanism.
In order to avoid this one needs to get into system users collection and create the new users documents and delete the old ones.

Connect to Mongo DB on MongoLab without Authorization?

My Question:
Is there any way to connect to Mongo DB (hosted on MongoLab) without username and password ?
My Case:
I have created a free MongoLab account (https://mongolab.com) and also create new database -> collection -> document in it.
When I connect to Mongo DB (on Mongo Lab) without username and password, I was able to connect, but when I try to retrieve any data it gives me "unauthorized db:testing lock type:-1 client:...." error.
So I have created a DB User in MongLab as well and provide username and password at the time of connection. After that I am able to connect and retrieve data from Mongo DB.
MongoLab's multi-tenant database plans are on shared servers. We cannot give you the choice to forgo authentication. Even if you were ok with others seeing you data, the other tenants on the server you share would still not want you to see their data.
We have dedicated server plans where you have your own server. On those we could turn off authentication for you. Email us at support#mongolab.com.
As for your benchmarks - auth will not slow things down. The drivers do not authentication on each request, just each connection. If you use the driver properly it should all work well.
-will (MongoLab)