Why am I getting – “Login Error { “serverUsed”: “MyServer.domain:27017″, “ok”: 0.0, “errmsg”: “auth failed”, “code”:18}”

 

When you login to JSON Studio you are really providing a username/password to connect to MongoDB and the Studio connects to MongoDB on your behalf. Because JSON Studio saves metadata to the database (e.g. for saved queries and graphs, for preferences, and more) you need to have write privileges in the Studio database to have a successful connection. Note that when you login to the Studio you have two database names – the main database that holds your data and the Studio DB. If you omit the Studio DB then the main database will also be used for the Studio’s metadata (and thus the user you use to connect-with should have write privileges). If you do not want this metadata saved in the same database remember to include a Studio database – in this case you only need read privileges to the main database.

JSON Studio first attempts to authenticate to the database you provided and if this fails it attempts to authenticate with the admin database. Therefore, you can define the user in the database you want to connect to or in the admin database. If you define the user in the admin database remember that the user definition needs to have privileges to read to the database you want to connect to (e.g. using a readAnyDatabase privilege) and a write privilege to the Studio DB (e.g. using a readWriteAnyDatabase privilege).

For example, if you want the qa1 user to be able to connect to the test database for querying and you want the metadata to be saved into the lmrm database, and you want the qa1 user defined in the admin database, then you need to provide the following privileges::

> db.createUser({user:"qa1", pwd:"qa1", roles: [{role: "read", db: "test"}, {role: "readWrite", db: "lmrm"}]})
Successfully added user: {
 "user" : "qa1",
 "roles" : [
 {
  "role" : "read",
  "db" : "test"
 },
 {
  "role" : "readWrite",
  "db" : "lmrm"
 }
]
}

 

If you want a user qa2 that can connect to any database for querying and write metadata to lmrm, provide the following privileges::

> db.createUser({user:"qa2", pwd:"qa2", roles: ["readAnyDatabase", {role: "readWrite", db: "lmrm"}]})
Successfully added user: {
 "user" : "qa2",
 "roles" : [
  "readAnyDatabase",
  {
   "role" : "readWrite",
   "db" : "lmrm"
  }
 ]
}

Note that the Studio database does not have to be in the same instance as the database you are querying. To use a Studio database on another instance provide the following connection URL in the Studio DB field::

<username>:<password>@<host>:<port>/<studio db name>

 

Posted in: Support