Integration between Mongodb and Buffalo Golang framework - mongodb

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 .

Related

mongodb atlas with symfony 3.4

I have symfony 3.4 and used Doctrine MongoDB Bundle
"doctrine/mongodb-odm": "1.1",
"doctrine/mongodb-odm-bundle": "3.4",
I have locally installed mongo and used with below configuration working fine.
mongodb_server: 'mongodb://mongo:27017'
mongodb_collection: test
doctrine_mongodb:
connections:
default:
server: "%mongodb_server%"
options: {}
default_database: "%mongodb_collection%"
but now i try to access mongodb atlas cluster at this time i have getting below error.
MongoClient::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known
i have trying to access using actual credentials as demo given
mongodb_server: 'mongodb+srv://<username>:<password>#clustertesting.osnmb.mongodb.net/<dbname>?retryWrites=true&w=majority'
mongodb_collection: test

Using MongoDB in Symfony Monolog Causes Error

The error I'm getting is like the following:
Some information that you should know:
I'm using Symfony 5
I'm able to connect to mongo db using MongoDB Compass and in terminal using mongo command
What packages I have installed are the following:
"mongodb/mongodb": "^1.6"
"monolog/monolog": "^2.0"
"symfony/monolog-bundle": "^3.5"
My configuration file monolog.yaml (config/packages/dev/monolog.yaml) is like the following:
monolog:
handlers:
mongo:
type: mongo
mongo:
host: localhost
Thank you.
I had installed mongodb with brew. And I figured out MongoDB\Client class was not recognized. Then I found that we can install mongo driver manually.
I followed the steps here : https://www.php.net/manual/en/mongodb.installation.manual.php
I've changed my monolog configuration file monolog.yaml as
monolog:
handlers:
mongodb:
type: mongo
mongo:
id: mongolog
I added MongoDB\Client as service into service configuration file services.yaml
services:
...
mongolog:
class: MongoDB\Client
And after doing things above, it's worked.

Assertion failure _setName.size on URI auth

I tried to much posibilities that I found searching for this error without success.
I can connect to my mongo with the CLI typing mongo --port myPort -u myUser ...
But I need to connect my app (in the same host) by URI.
This is what I get:
mongo mongodb://username:password#localhost:myPort/myDb
MongoDB shell version: 2.6.10
connecting to: mongodb://username:password#localhost:myPort/myDb
2017-05-19T23:34:33.568+0200 Assertion failure _setName.size() src/mongo/client/dbclientinterface.h 231
2017-05-19T23:34:33.569+0200 0x6b75c9 0x659e9f 0x636a32 0x5013b8 0x4fa7f1 0x6006fd 0x5eb869 0x7fdcdff35d76 0x1ebf47506362
mongo(_ZN5mongo15printStackTraceERSo+0x39) [0x6b75c9]
mongo(_ZN5mongo10logContextEPKc+0x21f) [0x659e9f]
mongo(_ZN5mongo12verifyFailedEPKcS1_j+0x142) [0x636a32]
mongo(_ZN5mongo16ConnectionStringC1ENS0_14ConnectionTypeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES9_+0x208) [0x5013b8]
mongo(_ZN5mongo16ConnectionString5parseERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS6_+0x201) [0x4fa7f1]
mongo(_ZN5mongo17mongoConsExternalEPNS_7V8ScopeERKN2v89ArgumentsE+0x11d) [0x6006fd]
mongo(_ZN5mongo7V8Scope10v8CallbackERKN2v89ArgumentsE+0xa9) [0x5eb869]
/usr/lib/libv8.so.3.14.5(+0x99d76) [0x7fdcdff35d76]
[0x1ebf47506362]
2017-05-19T23:34:33.570+0200 Error: assertion src/mongo/client/dbclientinterface.h:231 at src/mongo/shell/mongo.js:148
exception: connect failed
Any idea? :\ Thanks
Solved upgrading mongod from 2.6 to 3.0.15
If you don't want to upgrade to a newer version of MongoDB you can also just drop the mongodb:// from the beginning. For example change:
mongo mongodb://username:password#localhost:myPort/myDb
to:
mongo username:password#localhost:myPort/myDb
Ref: https://jira.mongodb.org/browse/SERVER-15739?focusedCommentId=1000536&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-1000536

Grails 3 MongoDB not reading connectionString from application.yml

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.

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.