Grails 3 MongoDB not reading connectionString from application.yml - mongodb

I am testing the Grail 3 application to connect mogoDB running on another server.
Standalone java program connect to database successfully. But Grail 3 application not able to connect to DB. Exception show its connecting to localhost.
I would like to understand why its not reading connectionstring from aplication.yml file.
application.yml file:
environments:
development:
grails:
mongodb:
connectionString: "mongodb://192.168.1.13:27017/test"
when I access the page, seeing this error message.
grails> 2017-02-14 22:52:28.116 ERROR --- [nio-8080-exec-9] o.g.web.errors.GrailsExceptionResolver : MongoTimeoutException occurred when processing request: [GET] /book/index
Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]. Stacktrace follows:
why its connecting to localhost?
tried from this answer didn't work.
Installing and using MongoDB in Grails 3.x
Thanks

This configuration work for me in both development and production.
environments:
development:
grails:
mongodb:
host: "localhost"
port: 27017
username: ""
password: ""
databaseName: "mydb-dev"
production:
grails:
mongodb:
host: "1.1.1.1"
# host: "localhost"
port: 27017
username: ""
password: ""
databaseName: "mydb-prod"
I'm using Grails 3.1.9 and latest MongoDB plugin.
compile 'org.grails.plugins:mongodb'

If you still want to use a connection string instead of supplying all of the parameters separately, you can use url as listed below:
environments:
development:
grails:
mongodb:
url: "mongodb://192.168.1.13:27017/test"
This approach also allows you to supply query parameters where necessary. The documentation can be found in the gorm manual under the MongoDB Connection Strings section.

Related

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 .

How to provide mongoSQLd Authentication failed ERROR 1043 (08S01)

To run BI on project we have used mongsqld to convert the JSON into tables.
On our first installation, everything was running fine and we were able to make analytics.
After installing the security on mongod, the monsqld failes to establish the connection with following error:
connection accepted from 127.0.0.1:44530 #11219 (1 connection now open)
handshake error: ERROR 1043 (08S01): MongoDB schema not yet available
end connection 127.0.0.1:44530 (0 connections now open)
Thanks in Advance.
It can also be the case that you haven't set up your mongosqld.conf correctly on your mongo bi connector side.
This will be evident if you check the log files for your mongosqld.conf and find that it has repeated entries for "[Sampler] sampling mongodb for schema permanently". In my case this happened all night until I fixed the config file.
In my particular case - I didnt configure authentication as per the following.
logAppend: false
path: "/var/log/mongosqld/mongosqld.log"
verbosity: 2
security:
enabled: true
mongodb:
net:
uri: "mongo.example.com:27017"
auth:
username: "root"
password: "changeme"
net:
bindIp: 192.0.2.14
port: 3307
As soon as I made the change, uninstalled mongosqld (sudo mongosqld uninstall), installed momgosqld with the new conf (sudo mongosqld install ), and restarted it - it worked.
More about the configuration here - https://docs.mongodb.com/bi-connector/master/reference/mongosqld/#std-label-config-format

Connection to Mongo DB Atlas using Elixir

I am trying to connect to Mongo Atlas using just Elixir mongo driver.
I wish there were enough help or code snippets around for making these external sharded connections with replica sets. Here's the error I've been receiving:
Mongo.Protocol (#PID<0.303.0>) failed to connect: ** (Mongo.Error) tcp connect: connection refused - :econnrefused
Connection start_link:
conn = Mongo.start_link(
database: "admin",
seeds: [
"server-shard-01:27017",
"server-shard-02:27017",
"server-shard-03:27017"
],
set_name: "test-shard-0",
username: "myuser",
password: "mypassword",
auth_source: "admin",
port: 27017,
type: "replica_set_primary",
ssl: true
)
I couldn't find any Erlang libraries helping here either. This could actually be due to the underlying Erlang libraries.
So alternatively we have implemented a Ruby code that does the writes to MongoDB and it runs as a separate container. Even though Elixir would let us run Ruby this is still not the best performing.
I would like to know if anyone else has found a solution for this yet?

Flyway cannot connect to db after Heroku Postgres upgrade

I am upgrading my heroku database from a hobby dev to Standard 0 (using the official instructions https://devcenter.heroku.com/articles/upgrading-heroku-postgres-databases#upgrade-with-pg-copy-default).
All went well, until I promoted the new database and restarted the app. I then get the following error:
o.s.boot.SpringApplication : Application startup failed
...
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Unable to obtain Jdbc connection from DataSource
...
Caused by: org.flywaydb.core.api.FlywayException: Unable to obtain Jdbc connection from DataSource
...
Caused by: org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "54.xxx.xx.xxx", user "u94bf9vxxxxxx", database "d2mqk0b6xxxxxx", SSL off
...
If I swap back to the old database again, everything works again. The only thing that I am changing is the promoted database.
Is there a difference between connecting to hobby and standard databases that I need to be aware of?
The relevant part of my application.yml looks as follows:
spring:
datasource:
driverClassName: org.postgresql.Driver
url: ${JDBC_DATABASE_URL}
username: ${JDBC_DATABASE_USERNAME}
password: ${JDBC_DATABASE_PASSWORD}
flyway:
enabled: true
locations: classpath:db/migrations
Any suggestions on how I can debug this would be very welcome too.
Looks like you aren't connecting with SSL where it is required by Heroku PostgreSQL installs.
See Herokus documentation on SSL for PostgreSQL.
See also Herokus documentation for enabling SSL on JDBC connections.
You will need to add something like &ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory to your JDBC URL.

SailsJS deployment to Heroku, connect to Mongolabs MongoDB

I am right now attempting my first Heroku deployment of a SailsJS API. My app uses SailsJS v0.11 andsails-mongo 0.11.2.
I have updated config/connections.js to include the connection information to MongoDB database I have hosted for free at Mongolab.
mongodb: {
adapter: 'sails-mongo',
url: "mongodb://db-user:password123#ds047812.mongolab.com:47812/testing-db"
}
Also updated config/models.js to point to that adapter.
module.exports.models = {
connection: 'mongodb',
migrate: 'safe'
};
This is basically all I have changed from running the code locally, when I deploy to Heroku the app crashes and I get this error...
/home/zacharyhustles/smallChangeAPI/node_modules/connect-mongo/lib/connect-mongo.js:186
throw err;
^
at Socket.emit (events.js:107:17)
2015-07-08T19:37:00.778316+00:00 app[web.1]:
at Socket.<anonymous> (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/connection.js:534:10)
Error: Error connecting to database: failed to connect to [localhost:27017]
How do I get rid of this, and make sure Sails does not try connecting to localhost db?
Ok, the problem was with storing sessions.
My solution was to setup a Redis database to store sessions.
In config/sessions.js make sure everything is commented out except for the method you want for session store.
Mine looked like this:
adapter: 'redis',
host: 'example.redistogo.com',
port: 1111,
db: '/redistogo',
pass: 'XXXXXYYYYYYXYXYXYYX',
This solved my posted problem, hope this helps another person out.