MongoDb user permission denied - mongodb

First I created mongoDB database and made it live AWS. Then I'm creating mongoDB database to MongoDb BI connector locally.
And I created Configuration file which is mentioned below:
security:
enabled: true
defaultMechanism: default
defaultSource: admin
mongodb:
net:
uri: MongoUrl
auth:
username: MongoUser
password: MongoPass
net:
bindIp: localhost
port: 3307
ssl:
mode: "allowSSL"
PEMKeyFile: "/mongo.pem"
MongoDB BI connector
And my cubeJS env file is this:
CUBEJS_DEV_MODE=true
CUBEJS_DB_TYPE=mongobi
CUBEJS_API_SECRET=9c7a834d9be0cd2fb4e7b86a88a2bd1368ffbc614dcf8fa8f836933b00d00c6916fa83b074c66a2b26579266edc93e0e1990b1271f6214ee799dc08b05b6a097
CUBEJS_EXTERNAL_DEFAULT=true
CUBEJS_SCHEDULED_REFRESH_DEFAULT=true
CUBEJS_WEB_SOCKETS=true
CUBEJS_DB_HOST=localhost
CUBEJS_DB_NAME=MongoDbName
CUBEJS_DB_USER=mongoUserName
CUBEJS_DB_PASSWORD=MongoPassword
CUBEJS_DB_PORT=3307
CUBEJS_DEV_MODE=true
CUBEJS_REFRESH_WORKER=true
port=4242
CUBEJS_DB_SSL=true
#CUBEJS_DB_SSL_CA=<SSL_CA>
#CUBEJS_DB_SSL_CERT=<SSL_CERT>
#CUBEJS_DB_SSL_CIPHERS=<SSL_CIPHERS>
#CUBEJS_DB_SSL_PASSPHRASE=<SSL_PASSPHRASE>
CUBEJS_DB_SSL_REJECT_UNAUTHORIZED=false
and Error is showing this:
Access denied for user
C:\Users\dell 7470>"C:\Users\dell 7470\Desktop\sql\mysql-8.0.31-winx64\bin\mysql.exe" --enable-cleartext-plugin --protocol tcp --port 3307 --user=hikarsmarttag --ssl-key=C:\mongo.pem --ssl-cert=C:\certificate.pem -p
Enter password: *****************
ERROR 1045 (28000): Access denied for user 'hikarsmarttag'
Whenever I try to connect to BI tools MySQL-Client, The same Error is being thrown.
Access denied in mySQL-Client

Related

Troubleshooting Mongoose Error - MongoNetworkError: failed to connect to server [localhost:27017] [duplicate]

I have just started learning about MongoDB and I am trying to host my node js application locally via MongoDB Server 6.0 (without using mongoose or atlas)
I copied the async javascript code given in the MongoDB docs. I made sure to run mongod before executing the below code
MongoDB server started
const { MongoClient } = require("mongodb");
// Connection URI
const uri =
"**mongodb://localhost:27017**";
// Create a new MongoClient
const client = new MongoClient(uri);
async function run() {
try {
// Connect the client to the server (optional starting in v4.7)
await client.connect();
// Establish and verify connection
await client.db("admin").command({ ping: 1 });
console.log("Connected successfully to server");
} finally {
// Ensures that the client will close when you finish/error
await client.close();
}
}
run().catch(console.dir);
It's throwing an error:
image of the error it's throwing
Problem is, the localhost alias resolves to IPv6 address ::1 instead of 127.0.0.1
However, net.ipv6 defaults to false.
The best option would be to start the MongoDB with this configuration:
net:
ipv6: true
bindIpAll: true
or
net:
ipv6: true
bindIp: localhost
Then all variants should work:
C:\>mongosh "mongodb://localhost:27017" --quiet --eval "db.getMongo()"
mongodb://localhost:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.6.0
C:\>mongosh "mongodb://127.0.0.1:27017" --quiet --eval "db.getMongo()"
mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.6.0
C:\>mongosh "mongodb://[::1]:27017" --quiet --eval "db.getMongo()"
mongodb://[::1]:27017/?directConnection=true&appName=mongosh+1.6.0
If you don't run MongoDB as a service then it would be
mongod --bind_ip_all --ipv6 <other options>
NB, I don't like configuration
net:
bindIp: <ip_address>
in my opinion this makes only sense on a computer with multiple network interfaces. Use bindIp: localhost if you need to prevent any connections from remote computer (e.g. while maintenance or when used as backend database for a web-service), otherwise use bindIpAll: true

Mongodb Compass: Connection timed out

I installed Mongodb on my remote server using this documentation. I have Ubuntu 16.04 on my remote server. Mongodb got installed successfully. I added the user like this:
use admin
db.createUser(
{
user: 'myuser',
pwd: 'password',
roles: [ { role: 'readWrite', db: 'mydb' } ]
}
);
I also made changes in the mongod.conf like this:
net:
port: 27017
bindIp: 127.0.0.1,<server_ip>
security:
authorization: 'enabled'
Now when I try to connect to mongodb using conneciton string like this:
mongodb://myuser:password#server_ip:27017/mydb
It gives me the following error:
connection timed out
What am I doing wrong here? I am using Laravel Forge to manage sever.
As it turned out the port was not open and that was the only issue. Opened the port and now its working fine.

Cannot connect to Postgres Database from Strapi on Google App Engine

Need help connecting to my Google SQL Postgres Database from Google App Engine. I've followed https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/deployment/hosting-guides/google-app-engine.html but keep running into the following error:
2022-09-27 16:11:32 default[20220928t020816] [2022-09-27 16:11:32.307] debug: ⛔️ Server wasn't able to start properly.
2022-09-27 16:11:32 default[20220928t020816] [2022-09-27 16:11:32.309] error: connect ECONNREFUSED /cloudsql/project-id:us-central1:database-id/.s.PGSQL.5432
database.ts
export default ({ env }) => ({
connection: {
client: 'postgres',
connection: {
host: env('DATABASE_HOST', '127.0.0.1'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'database-id'),
user: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false),
},
},
});
app.yaml
runtime: nodejs16
instance_class: F1
env_variables:
ADMIN_JWT_SECRET: 'XXXXXXXXXXXXX'
API_TOKEN_SALT: 'XXXXXXXXXXXXX'
APP_KEYS: 'XXXXXXXXXXXXX'
DATABASE_HOST: '/cloudsql/project-id:us-central1:database-id'
DATABASE_PORT: '5432'
DATABASE_NAME: 'database-id'
DATABASE_USERNAME: 'postgres'
DATABASE_PASSWORD: 'XXXXXXXXXXXXX'
DATABASE_SSL: 'false'
HOST: '0.0.0.0'
JWT_SECRET: 'XXXXXXXXXXXXX'
NODE_ENV: 'production'
PORT: '1337'
beta_settings:
cloud_sql_instances: 'project-id:us-central1:database-id'
One of the causes of error: connect ECONNREFUSED and the most common one when connecting to Cloud SQL using Unix Sockets (as is the case here) is that your GCP project does not have the Cloud SQL Admin API enabled.
Enable the Cloud SQL Admin API and that should help resolve the connectivity issue.

Connecting to a remote mongoDB server

I have a remote machine which I connect to using SSH, I installed mongoDB on it, and I wish to use it remotely, how do I connect to it using nodejs and mongoDB compass? the localhost is the IP ?
const db = "mongodb://what do I write here?";
const connectDB = async () => {
try {
await mongoose.connect(db, { useNewUrlParser: true, useCreateIndex: true });
console.log("MongoDB Connected...");
} catch (err) {
console.error(err.message);
process.exit(1);
}
};
connectDB();
Short answer
Login to your machine, open mongodb configuration file located at /etc/mongod.conf and change the bindIp field to your machine ip address (it is the same ip address which you are using to ssh to your machine), after that restart mongodb server.
Detailed answer
Open /etc/mongod.conf file using any of the editor, if you are running a desktop version then you can make use of gedit utility tool
sudo gedit /etc/mongod.conf
If you are running a server version, then you can make use of vi editor command
sudo vi /etc/mongod.conf
The file should contain the following kind of content:
systemLog:
destination: file
path: "/var/log/mongodb/mongod.log"
logAppend: true
storage:
journal:
enabled: true
processManagement:
fork: true
net:
bindIp: 127.0.0.1 // enter your ip address here
port: 27017
setParameter:
enableLocalhostAuthBypass: false
Once you change the bindIp, then you have to restart the mongodb, using the following command
sudo service mongod restart
Now you'll be able to connect to the mongodb server, with the same ip address which you are using to ssh to your system.
mongoose.connect('mongodb://<machine_ip_address>:27017/<database_name>')
mongoose.connect('mongodb://username:password#host:port/database')
Now for the host, is there any hostname or IP you could use?
Try this one:
mongoose.connect("mongodb://localhost/<database-name>", { useNewUrlParser: true });
const db = mongoose.connection
db.on('error', (error) => console.error(error));
db.once('open', () => console.log('Connected to Database'));
Make sure to run MongoDB
mongod --config /usr/local/etc/mongod.conf
first try this : mongoose.connect('mongodb://localhost:27017/database')
mongoose.connect('mongodb://<machine_ip_address>:27017/<database_name>')
mongodb://[username:password#]host1[:port1][,...hostN[:portN]][/[database][?options]]
check https://docs.mongodb.com/manual/reference/connection-string/
If you are using MongoDb Compass
Open 27017 port in Inbound of your Server
Form a link just like mongodb://11.11.111.11 in case you are not going to use auth
Click Connect
Basicly the link is mongodb://[username:password#]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]
More information here

user authentication not working on mongodb 3.6.5

I have installed mongodb 3.6.5 on aws ec2 server and setup following in .conf file
net:
port: 27017
bindIp: serverIP
security:
authorization: 'enabled'
then created user with following command in admin db and restarted mongodb
db.createUser(
{
user: "mydbuser",
pwd: "mydbpass",
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
}
)
now when I try to access db from console with following command if doesnt allow me and gives me error of authentication.
mongo serverIP --port 27017 -u "mydbuser" -p "mydbpass" --authenticationDatabase "admin"
Can someone help me what is wrong with it.
getting following error
MongoDB server version: 3.6.5
2019-01-11T08:46:50.245+0000 E QUERY [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow#src/mongo/shell/db.js:1608:20
#(auth):6:1
#(auth):1:2
exception: login failed
The method you are following is correct but there is some variations in mongodb while accepting credentials as string. You might need to enclose your username and password within single quote instead of double quote as follows.
mongo serverIP --port 27017 -u 'mydbuser' -p 'mydbpass' --authenticationDatabase 'admin'
Double quotes will work if you dont have special characters in your username/password.
For more details on mongo Check here https://docs.mongodb.com/manual/reference/program/mongo/