Getting this error when connecting mongodb in docker-compose with spring-boot application - mongodb

"ctx":"conn18","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-1","speculative":false,"principalName":"user","authenticationDatabase":"user_db","remote":"172.20.0.8:51928","extraInfo":{},"error":"UserNotFound: Could not find user "user" for db "user_db""}}
where user is my username & user_db is the database name

Add the authSource=admin at the end of the uri in spring-boot application.yml file
spring:
data:
mongodb:
uri: mongodb://user:pass#localhost:27017/user_db?authSource=admin

Related

Unable to connect to the database. Configure the url, user and password

I have a spring boot app and I need flyway migration. After I configured in application.yml like this:
flyway:
driverClassName: org.postgresql.Driver
locations: classpath:src/main/resources/db/migration
url: jdbc:postgresql://localhost:5432/myDB
user: postgres
password: 123
schemas: public
enable: true
baseline-on-migrate: true
I got an error when tried to use flyway:migrate or flyway:repair: Unable to connect to the database. Configure the url, user and password!
What I'm doing wrong?!

Integration between Mongodb and Buffalo Golang framework

I am trying to use buffalo framework (Golang) with Mongodb Database as database.yml file as follows:
development:
database: myproject_development
user: mongodb
password: mongodb
host: 127.0.0.1
url: mongodb://127.0.0.1:27017
test:
url: {{envOr "TEST_DATABASE_URL" "mongodb://mongodb:mongodb#127.0.0.1:27017"}}
production:
url: {{envOr "DATABASE_URL" "mongodb://mongodb:mongodb#127.0.0.1:27017"}}
But getting error as
Error:
level=error msg="Error: unknown dialect "mongodb" expecting one of cockroach, mariadb, mysql, postgres"
Additional:
And if you can add some links for the learning purpose of the same integration ,will be very helpful.
Thanks in advance .

Spring Boot + PostgreSQL: cannot find schema to create Camunda tables

I am trying to create tables for camunda (7.14.0) at Spring Boot application start. I have manually created a PostgreSQL schema in advance with the name "camunda". When I run the Spring Boot application, it gives me an error:
ENGINE-03017 Could not perform operation 'create' on database schema for SQL Statement ...
and
org.postgresql.util.psqlexception: no schema has been selected to create in
My application.yml config:
camunda:
bpm:
database:
type: postgres
schema-update: create
schema-name: camunda
username: camunda
password: camunda
table-prefix: camunda.
How can I create camunda tables in a schema with a specific name?
Example config:
spring.datasource:
url: jdbc:postgresql://localhost:5432/postgres?autoReconnect=true
username: cam1
password: cam1
driver-class-name: org.postgresql.Driver
camunda:
bpm:
database:
schema-name: cam1
table-prefix: cam1.
Ensure the schema has been created and user used has been given the permissions on the target schema.
Full example for two Camunda instances using separate schemas: https://github.com/rob2universe/two-camunda-instances

Issue with mongodb user authentication

I am trying to connect from SERVER-1 to my mongo server which is running in some other sever SERVER-2
So my grails app is running in SERVER-1. So I have given external configuration like this.
grails {
mongo {
host = "<SERVER-2>-host"
port = 27017
username = "myapp"
password = "myapp"
databaseName = "myapp"
options {
autoConnectRetry = true
connectTimeout = 3000
}
}
}
And in the SERVER-2 I've created myapp db and with the same user and credentials
use myapp
db.createUser( { "user" : "myapp",
"pwd": "myapp",
"roles" : [] },
{ w: "majority" , wtimeout: 5000 } )
And am able to see the users list like below
> db.getUsers()
[
{
"_id" : "myapp.myapp",
"user" : "myapp",
"db" : "myapp",
"roles" : [ ]
}
]
Mongo configuration contains "noauth=true",
And from SERVER-1, I'm able to connect to SERVER-2 mongo using the below command
mongo SERVER-2-HOST:27017/myapp -u myapp -p myapp
But when i try to connect from SERVER-1 grails application, its giving the below error
| Error Error executing script LoadVars: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'mongoTransactionManager' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mongodb.CannotGetMongoDbConnectionException: Failed to authenticate to database [myapp], username = [myapp], password = [m***p]
My mongod.conf file
# mongod.conf
logpath=/var/log/mongodb/mongod.log
logappend=true
fork=true
#port=27017
dbpath=/var/lib/mongo
pidfilepath=/var/run/mongodb/mongod.pid
# Listen to local interface only. Comment out to listen on all interfaces.
#bind_ip=127.0.0.1
# nojournal=true
#cpu=true
#noauth=false
auth=true
Am I missing anything here?
Looks like your MongoDB server is running and listening properly but not able to authenticate.
The first problem I'm seeing is that, you mentioned your Grails application is running on 1st server while your MongoDB server is on the 2nd, but the host in your DataSource.groovy configuration is configured to connect to the 1st host, not the 2nd. Is that just in the example or your code is really connecting to the 1st server (which is wrong)? Please verify it.
The second problem might be with the way you are adding the user to the database name myapp. Please follow these steps and try again after connecting:
1) Login to MongoDB instance on the 2nd host: mongo
2) Use your database use myapp
3) Verify that you don not have any user named myapp by running db.dropUser("myapp")
4) Now add the user:
db.createUser({
user: "myapp",
pwd: "myapp",
roles: [ "readWrite", "dbAdmin" ]
});
Now connect your Grails application.
Update
If you are using MongoDB 3.x and Grails 2.5.x or 2.4.x then this should be the problem of your authentication failure. I almost forgot to tell you this problem.
Grails somehow shipping the older version of Java driver i.e. 2.12.3 and to support MongoDB 3, we require minimum 2.13.x of Java driver. Also, the 3.0 Java driver is not a required upgrade for MongoDB 3.0. The 2.13.0 release is the minimum required for full compatibility with MongoDB 3.0.
https://github.com/mongodb/mongo-java-driver/releases/tag/r3.0.0
So, in your BuildConfig.groovy add this as dependency:
dependencies {
compile "org.mongodb:mongo-java-driver:2.13.1"
}
Also, if you are using Grails mongeez plugin, exclude the java driver from there:
compile (":mongeez:0.2.3") {
excludes("mongo-java-driver")
}
I'll create a ticket for this in Grails. Hope this helps!
Creating database-specific authentic user:
1. Run mongod from cmd
2. Run mongo from cmd
3. use "your_db_name"
4.
db.createUser(
{
user: "anik",
pwd: "password",
roles: [ { role: "dbOwner", db: "your_db_name" } ]
}
)
Take note of the db name. Insert urs.
5. mongo "your_db_name" -u anik -p password
6. Switch to your collections bson folder
7. mongorestore -d ss "abc.bson"
After Authentication you can connect to db using username password from your project properties file.
I got the issue with my setup.
Actually I was using grails mongo version 3.0.0
and I installed MongoDB 3.0.0. So according to this grails mongo documentation, grails mongo 3.0.0 plugin supports only MongoDB 2.6. But I was using 3.0.0(upgraded version).
Check this.
https://github.com/grails/grails-data-mapping/issues/557
So now MongoDB 3.0 doesn't support SCRAM-SHA-1 authSchema. So we should use some other techniques to authenticate our user.

Codeception and MongoDb. Configuration file

I would like test some data by codeception. And I don't know, how should correct set 'dns' in configuration file. I try this, but I get connection error
- MongoDb:
dsn: 'host=127.0.0.1:27017;dbname=test'
user: 'root'
password: ''
Add this config in your codeception.yml file
modules:
MongoDb:
dsn: mongodb://host:port/database