strapi Error connecting to the atlas Mongo database - database

I want to use mongo atlas with strapi. SO I am reading the values from .env
these are the settings
connections: {
default: {
connector: 'mongoose',
settings: {
host: env('DB_MONGO_URL', '127.0.0.1'),
srv: env.bool('DATABASE_SRV', false),
port: env.int('DB_PORT', 27017),
database: env('DATABASE_NAME', 'mydb'),
username: env('DB_USER_NAME', null),
password: env('DB_PASSWORD', null)
},
options: {
authenticationDatabase: env('AUTHENTICATION_DATABASE', null),
ssl: env.bool('DB_SSL_ENABLE', false),
},
},
and here are the values
DB_MONGO_URL=myproject.random.mongodb.net/mydbt?ssl_cert_reqs=CERT_NONE
DB_USER_NAME=myuser
DB_PASSWORD=mypasswor
but this is showing
[2021-10-12T13:18:25.485Z] debug ⛔️ Server wasn't able to start properly.
[2021-10-12T13:18:25.490Z] error Error connecting to the Mongo database. Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
error Command failed with exit code 1.
In network i have allowed, 0.0.0.0 that includes any IP address.
If i pass this url in MongoDB Compass
mongodb+srv://myproject.random.mongodb.net/mydbt?ssl_cert_reqs=CERT_NONE
then this works
I tried the same as well
DB_MONGO_URL=mongodb+srv://myproject.random.mongodb.net/mydbt?ssl_cert_reqs=CERT_NONE
DB_USER_NAME=myuser
DB_PASSWORD=mypassword
but this shows
[2021-10-13T06:59:01.372Z] debug ⛔️ Server wasn't able to start properly.
[2021-10-13T06:59:01.374Z] error Error connecting to the Mongo database. getaddrinfo ENOTFOUND mongodb+srv
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
If i tried enable srv true
[2021-10-13T07:01:20.065Z] debug ⛔️ Server wasn't able to start properly.
[2021-10-13T07:01:20.067Z] error Error connecting to the Mongo database. URI does not have hostname, domain name and tld
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
how can i solve this?

Related

heroku pg:push error with unexpected arguments - how to fix?

I am facing an issue when trying to run the command heroku pg:push postgres DATABASE_URL --app pyprodjangompz.
I get an error message saying
pg_dump: error: connection to server at "localhost" (::1), port 5432 failed: FATAL: password authentication failed for user "Usuario"
However, "Usuario" is not the name of my user in the local database. In my Docker information, it shows that the user name is "pythonpro" with password "pythonpro".
How can I resolve this issue and push my local database to Heroku?

NodeJS OracleDB connection string

I am running Oracle XE 21c in a Docker container and I can connect to it with a JDBC thin connection using the JDBC url jdbc:oracle:thin:#localhost:1521:XE using the SYSTEM account. I can also log into the terminal Docker instance and connect to the database fine.
When I try to connect to it using NodeJS OracleDB example code described here:
https://node-oracledb.readthedocs.io/en/latest/user_guide/connection_handling.html, I cannot get the client to connect using either:
connection = await oracledb.getConnection({
user : "hr",
password : mypw
connectString : "localhost/XEPDB1"
});
or
connection = await oracledb.getConnection({
user : "SYSTEM",
password : "MyPassword",
connectString : "localhost/XE"
});
I get an error ORA-01017: invalid username/password; logon denied.
I can connect to Oracle XE using sqlplus either by logging into the Docker container or from the host Mac using:
sqlplus SYSTEM/Password#localhost:1521/XE
if I change the nodejs code to:
const connection = await oracledb.getConnection({
//user: "SYSTEM",
//password: "Password42",
//connectString: connectionURI.url
connectString: "SYSTEM/Password#localhost:1521/XE"
});
I get the error:
ORA-12154: TNS:could not resolve the connect identifier specified
Any ideas why I can connect with sqlplus but not NodeJS OracleDB?

Django on Google cloud

I am new to both GKE and Django. I made an app in Django, made a docker container and push it to gcr and deploy it via GKE. The deployment works fine but when i try to login, I got the OperationalError. For database connection, I am using CloudSQL proxy.I have collected the static file and stored in google storage. Any help will be highly appreciated.
I have tried quite many opinions available already online but failed to succeed.
When i try to login as admin, I got the following output after input my username and password for login.
OperationalError at /admin/login
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
Following are my database setting in Django.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'polls',
'USER': os.getenv('DATABASE_USER'),
'PASSWORD': os.getenv('DATABASE_PASSWORD'),
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
error while trying to login as admin
You should check in the docker logs , and check if there is any error connecting to the database
If it is a databse connection issue, then you can try the following in your docker-compose.yml . You can customize the rest of the variables mentioned, as needed for your polls application
you can try this
web:
build: ./app
image: {imagename}
depends_on:
- cloud-sql-proxy
environment:
- SQL_ENGINE=django.db.backends.postgresql_psycopg2
- SQL_DATABASE=test_db
- SQL_USER=postgres1
- SQL_PASSWORD=6728298
- SQL_HOST=cloud-sql-proxy
- SQL_PORT=5432
- DATABASE=postgres
cloud-sql-proxy:
image: gcr.io/cloudsql-docker/gce-proxy:1.11
command: /cloud_sql_proxy -instances=<INSTANCE_CONNECTION_NAME>=tcp:0.0.0.0:5432 -credential_file=/config
volumes:
- {service_account_creds_path.json}:/config
You could read this article https://adilsoncarvalho.com/how-to-use-cloud-sql-proxy-on-docker-compose-f7418c53eed9 for reference. The article is about mysql, but the concepts are the same . Good Luck!

Cloud SQL from App Engine (flexible environment) connection issue

I'm trying to access my Cloud SQL instance from my App Engine flexible environment NodeJS application but kept getting timeout issues.
When I add the IP of the compute engine running the App engine to the Cloud SQL Access Control it works. The documentation states that access should be granted automatically if both are in the same project.
What am I missing?
I'm using the following connection settings for knex:
const config = {
host: 'myIP',
user: 'user',
password: 'password',
database: 'database',
port: 3306
};
The socket settings aren't working either. throwing a "Unhandled rejection Error: connect ENOENT /cloudsql" exception:
const config = {
socketPath: '/cloudsql/project:zone:instance',
user: 'user',
password: 'password',
database: 'database'
};
This error most likely indicates that the proxy process is not running on the GAE Flexible instance.
As per the documentation, you must have cloud_sql_instances set in your app.yaml file for the proxy to be automatically started.

Connecting to Cloud SQL Proxy with PDO

I'm following this tutorial except that I do not wish to use Silex.
I have set up a Cloud SQL Second Generation instance and a local proxy, which I can successfully connect to using SQL Workbench. This is the code I'm using to connect with:
define('DBH_SOCKET', '/cloudsql/project-***:us-east1:instance-****');
define('DBH_NAME', 'testdb');
define('DBH_USER', 'root');
define('DBH_PASSWORD', '****');
$pdo = "mysql:unix_socket=".DBH_SOCKET.";dbname=".DBH_NAME.";charset=utf8";
try {
$db = new PDO($pdo, DBH_USER, DBH_PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e){
echo 'Connection failed: ' . $e->getMessage();
}
echo '<br />';
if($db) echo 'YAY'; else echo 'NAY';
It works absolutely fine when I deploy the app an visit project-***.appspot.com, but the connection fails when I try to work locally.
Connection failed: SQLSTATE[HY000] [2002] No such file or directory.
I know this question has been asked before in various contexts, but none of their solutions are working for me or don't directly apply. I have added this to my app.yaml file with no change in results:
env_variables:
# Replace project, instance, database, user and password with the values obtained
# when configuring your Cloud SQL instance.
MYSQL_DSN: mysql:unix_socket=/cloudsql/project-****:us-east1:instance-****;dbname=testdb
MYSQL_USER: root
MYSQL_PASSWORD: '****'
beta_settings:
cloud_sql_instances: "project-****:us-east1:instance-****"
Why can't I connect locally using PDO when I can connect locally using my SQL client?

Resources