I have created a database in Hostinger and make it remote. But, when I try to connect with my local using nodejs I am getting an error: "ER_ACCESS_DENIED_ERROR" even after using the right username and password.
This is my code below:
Have I done anything wrong? Please help me
This error usually occurs if the credentials are incorrect or the user can not access the database.
Also, In an express app, it is usually better to re-use the database connection instead of connecting to the database on every request.
Related
Hello I'm trying to connect sequileze to my database that I have in mysql I'm following a step by step tutorial but I get this error and I'm entering both the password and the user and does not let me make the connection I tried on another device and it worked, can someone help me?
I wanted to make the connection with sequileze to mysql.
From the terminal, the application launches and connects with MongoDB, but when I attempt to access it at the IP address of the droplet (with the correct port), I am getting an error:
MongoError: not authorized on cmf to execute command (cmf is the dbname).
I followed the install & setup instructions here, creating a user and afterward added the role of root described here. This was for the admin database.
When logged into the Mongo shell, I can access data thru db.status(), and when using admin db I can run show users and see the user.
I am confused whether I lack configuration for the cmf database. When using cmf db, when I run show users, nothing is returned.
For unknown reasons, the application cannot connect with mongodb. I am now thoroughly confused about where to go from here.
If anyone can point me in the right direction, I would appreciate it.
You need to create the database user with password (like in the tutorial included in your question), then upon connecting:
var dbHost = 'mongodb://username:password#localhost:port/cmf';
mongoose.connect(dbHost);
Where:
username is the username of created user,
password is the password,
port is the correct port of running mongodb (defaults to 27017).
I've connected to mLab using MongoClient.connect, but now I want to create a local database rather than use mLab. I've tried changing the URL to "mongodb://localhost:27017/mydb" to create a database locally as suggested, but I'm getting a failed to connect to server error. Is there anything I should install? Or am I just missing something?
First, install your mongoDB server:
https://docs.mongodb.com/manual/installation/
After that, you should be able to start your local mongodb server:
sudo service mongod start //in case of linux
Here the docs to start the mongodb server
Then, you will type mongo and the client command line will start.
And when typing use yourDatabase, mongo will create the database if
it does not exist.
Then, your server will be up, and the database created. Anyway, check the docs if you need the guides for windows or other systems.
First you need to understand how server works and mlab works. mLab is a company who provide database as a services. Means you no need to handle server hurdles, they take care server , backups , infrastructure etc. They provide mongodb server , You just need to create database on mongodb server's and use them.
Now comes to main points.
If you want use mongodb on your local system then you first need to install mongodb on your local system and then connect it.
So I have this API app running on my machine, and a MongoServer running on another computer in the same local network.
I have figured that this has to have something to do with the fact that the mongoserver is on another host, because the same Models and Schemas work fine when app is running on same host as server.
I can successfully make GET requests, however when I try to make a POST request my app crashes saying that my schema validation failed.
Do I need to make any extra authentication for that? If yes, how do I go about that?
I created a NodeJS app that connects with a MongoDB and it seems to work locally.
Now, after hosting the NodeJS application on a remote machine, I am trying to connect to a mongoDB that was already created on that machine. When I print out some of the environment variables, the only one I see of relevance seems to be :
MONGODB_PORT: 'tcp://172.30.204.90:27017',
I tried connecting like I usually do with
mongoose.connect('mongodb://localhost:27017/metadata/')
and replacing it with mongoose.connect('tcp://172.30.204.90:27017/metadata') but I get an error that says my URI needs to start with 'mongodb'.
So I tried replacing it with mongoose.connect('mongodb://172.30.204.90:27017/metadata') and it no longer throws any error. But on the MongoDB side I don't see any new connections happening and my app does not start up on the machine. What should I be putting in the URI?
Your URI should indeed start with mongodb:
mongoose.connect('mongodb://username:password#host:port/database?options...');
See this page for more information: https://docs.mongodb.com/manual/reference/connection-string/
Did you try to connect to the database from cli? Or Telnet to see that connection isn't blocked.