After installing mongo db in my project with express js i am mongo db is not connecting why? - node.js

Please help me to find the what is mean by connect ECONNREFUSED 127.0.0.1:27017

If you are using windowsOs then go to task manager -> services -> click on mongodb -> click on services button on the right bottom of the tab -> click on start .. this should restart your mongodb server and fix the issue.
If you are using a command prompt/ terminal then just restart your mongodb server.
https://www.youtube.com/watch?v=xgpGmi0EgcA
This video might help.

Related

How to get standard URI connection string (without srv) on mongodb website with current update?

I have made a cluster on mongodb website, whitelisted IP adress, added the user and connected my application, but it is not giving me 'Standard URI connection' option (maybe their website got updated) instead it is giving me one with srv. So when I used it in mongoose.connect() function it is giving me error:"Invalid Uri,Must begin with mongodb://"...
I have been working to connect to mongodb for so long but failing every time
You have created cluster on MongoDB Atlas? Right.
If using mongo application:
change nodejs version to 2.12 or later from connect your application screen.
If using mongo shell:
On the "Connect to Cluster0" page, select I have mongo shell installed, then select mongo shell version "3.4 or earlier". You will get the desired format.

Using mLab on Google App Engine through Wiki.js (Connection timeout)

I'm trying to set up a Node.js application using wiki.js: https://github.com/Requarks/wiki
I just started with Google App Engine and using their Cloud Shell. I installed Wiki.js using their bash command and ran a command that ran a server on port 3000 which I then used Google's shell to view.
It brings you to Wiki.js' configuration UI where you insert info including the mongodb connection string.
I have a DB in mlab set up with a user. I tested it locally to make sure I can connect, but when I try to do this process through the Google App Engine "Web Preview" they have on their command line, on the step where I am to add the mongodb connection string, it times out, giving the error:
Error: failed to connect to server [secret.mlab.com:secret] on first connect [MongoError: connection 8 to secret.mlab.com:secret timed out]
(i hid the actual address)
So i'm wondering if I'm missing something with this Google App Engine, since this connects successfully on my localhost

Resource temporarily unavailable. Authentication by key failed (Error -18). (Error #35)

I'm using EC2 Amazon Web Service to launch my server using NodeJS, MongoDB.
I completed to save and load the data using my android application through NodeJS server and MongoDB but when I tried to check the data using RoboMongo (Robo 3T), the error occurred.
Resource temporarily unavailable. Authentication by key (path of the .pem key) failed (Error -18). (Error #35)
Robomongo 1
Robomongo 2
Error dialog
This is what I did in Robomongo.
These are the result of searching the google... I think I did right...
What is wrong?
I Solved the problem myself.
When you have this problem,
1. Check out /etc/mongod.conf
In network interfaces.
bindIP must be 0.0.0.0
not 127.0.0.1
2. Check the SSH User Name.
For an Amazon Linux AMI, the user name is ec2-user.
For the others, Check out the link ! https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html
3. If it didn't help,
try to download what developer uploaded (1.2 - Beta)
https://github.com/Studio3T/robomongo/issues/1189#issuecomment-353279070

Using Google CloudSQL, getting "connect ECONNREFUSED 127.0.0.1:3306"

I'm trying my best to learn Google's Cloud Platform. They have a CloudSQL offering, which I'm learning via this NodeJS tutorial. Everything worked great until I deployed to their appspot server, at which point I got the following error:
connect ECONNREFUSED 127.0.0.1:3306
I've looked all through the NodeJS project and don't see anything in it or the Cloud Console that is referencing localhost or 127.0.0.1. Googling the error hasn't helped thus far. Any ideas?
I couldn't get this thing fixed when running on server but using this files I was able to read/write from local and production, now im using this connection strings in my own app
https://cloud.google.com/appengine/docs/flexible/nodejs/using-cloud-sql
https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/appengine/cloudsql
I had a similar issue when deploying the nodejs sample app 2-structured-data
The reason why the error occurred is that the NODE_ENV environment variable was not passed to the config file that is used to check if node should use a socket for connecting to mysql
You can fix it by adding 'NODE_ENV' in the file config.js :
.env([
...
'NODE_ENV'])

Cannot fetch from or insert data to mongodb using mongoose

I wrote a node web app and created a mongoDb database on my local system. I was using the following code to connect to local mongodb from node js
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/db_name'); //local
And everything was working fine on my local machine. So I went on and created an mlab account and created a database. But when I tried to run the code by changing the connection string, connections are still established I believe. But the find and save requests are not invoking the callbacks, even no errors shows up. All requests are getting timed out.
var mongoose = require('mongoose');
mongoose.connect("mongodb://user:pass#ds036789.mlab.com:36789/db_name"); //mlab
Another thing I noticed is that I cannot ping ds036789.mlab.com. But TCP connections are succeeding when I tried the nc command
nc -w 3 -v ds036789.mlab.com 36789
I even tried deploying to azure. Which doesn't work either. Any help is much appreciated. Thanks.
EDIT:
Not being able to ping was due to the fact that I used azure hosting. It is expected. And I also found out that I get this error while trying to connect :
connection error: { [MongoError: auth failed] name: 'MongoError', ok: 0, errmsg: 'auth failed', code: 18 }
Credentials are correct though.
From the error mesasge it seems like you are using invalid auth details
This is most likely happen when you do not create username and password for individual database i.e, db_name in you case.
Check mLabs account and create username and password for db_name database and update your connection string.
According to the error information, as #Astro said, it seems to be caused by using invalid auth user/password which be created for database.
Did you create a new user for connecting the database, not account user for mlab? Such as the figures below shown.
Fig 1. A database user is required for connecting
Fig 2. Users list for the database
Hope it helps.
I figured out the issue, it wasn't an issue with the credentials. It was an issue with the mongoose version. The mongoose version I used didn't support the authentication. I had to remove the package and reinstall the latest version. with
node install mongoose#latest
Hope it helps someone. And thanks for the answers :)

Resources