I used the JDBC driver as noted above in the pom.xml from Maven.
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-jdbc</artifactId>
<version>2.0.0</version>
</dependency>
I used the JDBC driver as noted above in the pom.xml from Maven.
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-jdbc</artifactId>
<version>2.0.0</version>
</dependency>
Because there is not collection named system.users in the corpus_test database.
Because there is user named corpus in the corpus_test database. It’s _id is corpus_test.corpus as per your own post. So it fails because the user already exist.
It doesn not show the corpus_test user but the user corpus of the corpus_test database. All users, even defined in another database are in the collection system.users of the admin database. The field named db of the user data indicates the authentication database.
It is not correct since it does not work.
You should
use admin
You createUser command seems the right one when executed after use admin.
Yep, I created the user in admin database, using that command, as I stated above.
I’m going to take five on MongoDB.
Thanks for all the replies!!!
Please share output of:
use admin
db.getUsers()
use corpus_test
db.getUsers()
Ok, here is what my final impression after trying to use mongodb-jdbc
too. (I say trying, because no clear how-to exists, and I fail by Command failed with error 59 (CommandNotFound): 'no such command: 'sqlGetResultSchema'' on server
. yet, take note that I still do connect)
Now, the following steps will cost you only about 350MB for initializing a new data folder. But I want you to follow every step, and see if your app connects or not. my test app all succeded to connect (yet I couldn’t make them run further than that) so if your app fails to connect blame the app. if you do connect to this 27001, then blame your 27017 server settings (blame and then go fix it).
mkdir testjdbc
cd jdbc
mkdir data
mongod --port 27001 --dbpath ./data --noauth
open a new terminal and connect to the server
mongo --port 27001
In mongodb shell:
use admin
db.createUser({
user: "admin",
pwd: "adminpas",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
})
use corpus_test
db.createUser({
user: "corpus",
pwd: "passpass",
roles: [ { role: "readWrite", db: "corpus_test" }]
})
use admin
db.shutdownServer()
Then again in the previous console:
mongod --port 27001 --dbpath ./data --auth
and your url has no change except authMechanism=DEFAULT
since Unsupported authMechanism: DEFAULT
"jdbc:mongodb://corpus:passpass@localhost:27001/?authSource=corpus_test"
you will also see logs with this line when your app connects having "Authentication succeeded"
. any mismatch between server and app url will result in UserNotFound
or AuthenticationFailed
PS: admin user is there in case you want to change things without restarting, or just if you like this 27001 and want to keep it around.
This still throws the error in Java code that: “There are issues with your connection settings : Mandatory property ‘database’ is missing.”
There are two JDBC maven possibilities.
I’m using:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-jdbc</artifactId>
<version>2.0.0</version>
</dependency>
But there is also:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.11</version>
</dependency>
This 3.12.11 dependency doesn’t work with any of the Class.forName(…) examples listed. Just does not work.
It’s been a long discussion so easy to miss parts
In one of my replies above, I have given a modified source to test the connection. So in short we were testing the connection so far.
Now, what you see is not the connection error, but instead, it is one of database/collection/document errors. That means (at least to me) you have corrected connection problems and now the rest is history
From now on, you need to check documentation on how to do CRUD operation. I had a commented line in the same post above. You can try that one for simple testing.
//stmt.execute("use corpus_test;"); // use this or embed after hostname "localhost:27017/corpus_test"
PS: here in my code, “corpus_test” becomes both your auth database and work database. so heads up if you change auth and work databases.