MongoDB connection problems - node.js

I am trying to connect MongoDB with node.js but whenever I try I am getting this error. (MongoDB is started).
[terminal]JavaScript code
I tried to restart MongoDB.

I found the solution, by replacing the URI from (mongodb://localhost:27017) to
(mongodb://0.0.0.0:27017).
And it worked for me.

Related

server crushes after linking mongo atlas,

Server crushed when i linked mongo atlas on the server.js file,error being generated is connection.once is not a functionserver.js file
I have tried to require once as an eventemitter but with no success
I think the way you have implemented this is wrong. When I am looking at another example i.e Mongoose.connection('once') what does it mean it has applied db.once on a DB where as you are doing it on a connection

Mongodb connection failed in local with node version 18.12.0?

I am seeing one issue with node version 18.12.0 and mongodb 6.0.2. I already build a nestjs application with mongodb. Here I use #nestjs/mongoose(v- 9.0.2) and mongoose (v-6.7.0)
Here I can see that when I upgrade node js to latest lts version then I am not able to connect to mongodb. It show an error like unable to connect to database.
But When I downgrade to node version 16.18.0 then it working fine. My question is that you guys already face this issue or I am only person getting this issue. If you know that then actually where is the problem occurred?
Here is my connection code-
MongooseModule.forRoot("mongodb://localhost:27017/nekmart", {
connectionFactory: (connection) => {
connection.plugin(slug, { number: true });
return connection
}
}),
Had same problem after upgrading to NodeJs 18.12.1; followed other blogs/comments and apparently
changing the Uri from mongodb://localhost:27017/test_db to mongodb://127.0.0.1:27017/test_db works.
Without getting into the specifics reasons it appears that localhost is rejected due to some changes in NodeJS.

Handling Mongoose connection failure in NestJS

I am new to NestJS.
I am trying to connect to mongo instance, like this MongooseModule.forRoot('mongodb://localhost:27017/demo')
How can I handle no connection here.
Probably you wrote wrong database URL.
You have to follow official documentation:
Mongo

How to handle Database Connection Error while running app using Sequelize?

I am having an issue that if Node server application is already running using Sequelize, then Database server has been crashed then it also close node process, how to handle it ?
I also checked on Sequelize repo issue https://github.com/sequelize/sequelize/issues/1854
But error events not implemented yet.
Any idea, Thanks in advance

Auth failed, code 18 when connecting to MongoLab database

I'm trying to connect to a MongoLab database but keep getting the following error on connection:
{ [MongoError: auth failed] name: 'MongoError', ok: 0, errmsg: 'auth failed', code: 18 }
The code I'm using to connect is:
var mongoose = require("mongoose");
mongoose.connect("mongodb://username:password#ds061474.mongolab.com:61474/apitest");
mongoose.connection.on('error', function (err) {
console.log(err);
});
When I connect using the shell, I have no problems whatsoever. What am I doing wrong?
I have encountered similar problem when connecting the mongo db using mongoose. After exploring a while I found mongoLab is using SCRAM-SHA-1 authentication.
Refer to the question below I tried to upgrade my mongoose to V4.1.11, and then it works for me
Authentication in mongoose using SCRAM-SHA-1
I faced the same issue while I try to import data from the locale to server.
Those 2 parameters can be important, it worked after I put them:
--authenticationMechanism 'MONGODB-CR'
--authenticationDatabase "admin"
Be careful about the auth mechanism, can be a different one. Check this part of documentation: https://docs.mongodb.com/manual/reference/program/mongoimport/#cmdoption-mongoimport-authenticationmechanism
Had this error myself, turns out I did two things incorrectly (thanks Idos):
Used the mongolab.com username instead of the database one.
Tried to connect to a mongo 3.4 database using a 2.6 shell provided through Ubuntu's repositories. mongo --version to check.
Follow the instructions from this MongoDB page to add their keys and repositories to your APT sources in order to upgrade and keep your MongoDB installation updated going forward.
i had a similar error in that case. put authSourse=admin and ssl=true to your connection
e.g
mongodb://username:password#ds061474.mongolab.com:61474/apitest?authSourse=admin&ssl=true

Resources