mongodb atlas with symfony 3.4 - mongodb

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

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 .

connecting to mongodb replicaSet with nestjs and typeorm is not working

problem
I'm trying to connect to mongodb with nestjs(^8.2.3) and typeorm(^0.2.28)
In test environment, connecting to mongodb standalone server is working. For your information, node mongodb library version is ^3.6.2.
production sample code(nestjs server)
I referred the typeorm code to write mongodb options
import { TypeOrmModule } from '#nestjs/typeorm';
import { MongoConnectionOptions } from 'typeorm/driver/mongodb/MongoConnectionOptions';
export const configForOrmModule = TypeOrmModule.forRootAsync({
imports: [],
useFactory: async () => {
const mongodbConfig: MongoConnectionOptions = {
type: 'mongodb',
username,
// for replicaSet (production)
hostReplicaSet: 'server1.example.com:20723,server2.example.com:20723,server.example.com:20723',
replicaSet: 'replicaSetName'
port: Number(port),
password: encodeURIComponent(password),
database,
authSource,
synchronize: true,
useUnifiedTopology: true,
entities: [Something],
};
return mongodbConfig;
},
inject: [],
});
But in production environment, when nestjs server try to connect to mongodb replicaSet, the server get this server selection loop error message over and over again like below. Interesting thing was the domain that the server tried to connect was different from replicaSet hosts(ex. another-hostname not included in server1.example.com:20723,server2.example.com:20723,server.example.com:20723). (+ edited: the another hostname is actual physical server indicated by the dns(server.example.com))
[39m01/28/2022, 2:39:16 AM [31m ERROR[39m [38;5;3m[TypeOrmModule] [39m[31mUnable to connect to the database. Retrying (3)...[39m
MongoServerSelectionError: getaddrinfo ENOTFOUND <another-hostname>
at Timeout._onTimeout (/home/node/app/node_modules/mongodb/lib/core/sdam/topology.js:430:30)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)
what I’ve tried but these not worked
remove useUnifiedTopology: true option
downgrade mongodb library version to 3.5.11 (I've read in mongodb community there are something bug with topology after 3.6 version)
use host option not the hostReplicaSet
if you need more information, please tell me. thank you for your helping.
It was kubernates DNS issue. The hostReplicaSet server1.example.com:20723,... is resolved to host1 (physical server name. without example.com) but, k8s doesn't know it. so connection was failed.
there are two options
update kubernates /etc/hosts setting to add host1 -> host1.example.com
or update mongodb hostname host1 -> host1.example.com

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.

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.

Error in connecting to mongodb (mongodb-linux-x86_64-2.8.0-rc5) : auth failed, when starting nodejs appserver

I am new to mongodb, I am able to get my nodejs appserver started with mongodb 2.4 and 2.6. I have a requirement to test the latest mongodb, which is 2.8 with our app. I am able to start the mongodb 2.8 but when I try to start my nodejs appserver, I get following error.
2015-01-16T18:43:51.115Z <warn> globals.js:45 () MONGO URI = mongodb://myuser:password#localhost:27017/test
2015-01-16T18:43:51.178Z <error> globals.js:45 () #### Error in connecting to mongodb
2015-01-16T18:43:51.180Z <error> globals.js:45 () { [MongoError: auth failed] name: 'MongoError', ok: 0, errmsg: 'auth failed', code: 18 }
2015-01-16T18:43:51.182Z <error> globals.js:45 () MongoError: auth failed
.........
Also, I have created myuser in the test db and authenticated it successfully. Please help, I have tried all possible ways and with no success. Thank you very much in advance. (my environment is Ubantu Linux 14.04, virtualbox) One more thing that I forgot to mention is that I am using wiredTiger storageEngine. I tried with MMAPv1 as well and same result.
I had the same issue. It worked for me on Mac, but on Linux I hit this failure until I upgraded module mongoose from 3.6.x to 3.8.x (3.8.25). That solved the problem for me. You might consider doing the same, at least to rule out this problem.