Heroku fails to load page. MongoError: Authentication failed - node.js

I been trying to upload my app to Heroku But I keep getting this MongoError: authentication fail error. I have both username and password correctly. Can someone help me out. I tried installing different version But no use.
running mongod --version
db version v3.4.4
git version: 888390515874a9debd1b6c5d36559ca86b44babd
In my package.json I have
"dependencies": {
"mongoose": "^4.4.12",
"mongoose-unique-validator": "^1.0.2"
},
app.js
var mongoose = require('mongoose');
mongoose.connect('<username>:<password>#ds129023.mlab.com:29023/ng2');
heroku logs:-
throw er; // Unhandled 'error' event
MongoError: Authentication failed.
at Function.MongoError.create (/app/node_modules/mongodb-
core/lib/error.js:31:11)
at /app/node_modules/mongodb-core/lib/connection/pool.js:497:72
^
at authenticateStragglers (/app/node_modules/mongodb-
core/lib/connection/pool.js:443:16)
at Connection.messageHandler (/app/node_modules/mongodb-
core/lib/connection/pool.js:477:5)
at Socket.<anonymous> (/app/node_modules/mongodb-
core/lib/connection/connection.js:321:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:547:20)
Thanks

You are not providing protocol name here
var mongoose = require('mongoose');
mongoose.connect('mongodb://<username>:<password>#ds129023.mlab.com:29023/ng2');
I added mongodb before username. Try with this, it should work.

I had the same problem.
Make sure that you've created a user for your database
For case with "admin" user, it could be:
mongoose.connect('mongodb:admin:#ds129023.mlab.com:29023/ng2');

I have faced the same problem in my case I have not added config vars in Heroku app.
Go to Heroku website > Your App > Settings > Reveal Config Vars and add your environment variables there.
As You Can see in the following image.

Related

error: database "dbName" does not exist Node.js PostgreSQL

I'm just starting with Node.js and I'm following this tutorial https://dev.to/glaucia86/developing-a-crud-node-js-application-with-postgresql-4c9o
when setting .env file as suggested
DATABASE_URL=postgres://{db_username}:{db_password}#{host}:{port}/{db_name}
so
DATABASE_URL=postgres://vinnytwice:pass#localhost:5432/fixit
I start the server with npm start command when using Postman to send a Post request I get they error in console:
vinnytwice#Vinnys-iMac fixit_server_node % npm start
> fixit_server_node#1.0.0 start
> node server.js
App executing to port 3000
error: database "vinnytwice" does not exist
at Parser.parseErrorMessage (/Volumes/ProjectsSSD/FixitServer/fixit_server_node/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/Volumes/ProjectsSSD/FixitServer/fixit_server_node/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/Volumes/ProjectsSSD/FixitServer/fixit_server_node/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.<anonymous> (/Volumes/ProjectsSSD/FixitServer/fixit_server_node/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:369:20)
at addChunk (node:internal/streams/readable:313:12)
at readableAddChunk (node:internal/streams/readable:288:9)
at Socket.Readable.push (node:internal/streams/readable:227:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
What am I doing wrong ?
Many thanks.
Finally found the problem, the .env file wasn't at the root of the project.

MongoDB error while installing Rocket.chat in CentOS 8 server with Apache

I am following this tutorial to install a Rocket.chat server in CentOS:
https://hostpresto.com/community/tutorials/how-to-install-rocket-chat-server-on-centos-7/
I am new to mongodb and node.js so I am not very familiar with how all this works
At the moment I am looking for something simple that just works
When I reach the step where it says to execute
node main.js
I get the following error:
[username#localhost Rocket.chat]$ node main.js
/opt/Rocket.chat/programs/server/node_modules/fibers/future.js:313
throw(ex);
^
MongoError: not master and slaveOk=false
at Connection.<anonymous> (/opt/Rocket.chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/pool.js:450:61)
at Connection.emit (events.js:310:20)
at processMessage (/opt/Rocket.chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/connection.js:384:10)
at Socket.<anonymous> (/opt/Rocket.chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/connection.js:553:15)
at Socket.emit (events.js:310:20)
at addChunk (_stream_readable.js:286:12)
at readableAddChunk (_stream_readable.js:268:9)
at Socket.Readable.push (_stream_readable.js:209:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
ok: 0,
errmsg: 'not master and slaveOk=false',
code: 13435,
codeName: 'NotMasterNoSlaveOk',
[Symbol(mongoErrorContextSymbol)]: {}
}
The tutorial says I should be able to see the Rocket.chat web interface if I go to https://yourdomain.com:3000 but I get an unable to connect page, which I suppose is due to the error above
The tutorial also says node main.js is to check if MongoDB is running or not. I can see that MongoDb service is running by executing
systemctl status mongod
so this error seems to be caused by something else.
How do I find out what is causing this error? Or are there any mistakes in this tutorial? I have found other tutorials regarding installing Rocket.chat in CentOS but most of them use nginx as hte web server while I need to use Apache.

MongoError : command createIndexes requires authentication - mongodb npm

I have a project that I recently put in a production server (not live, but different from my development environment). I configured a mongoDB server with a password authentication.
When I start my Nodejs Application, my usual code retrieve correctly my mongoDB server, returning a client.db object successfully.
But I also have an error popping-in. Something that is not called inside my Nodejs application apparently.
[ERROR] { MongoError: command createIndexes requires authentication
at Connection.<anonymous> (/home/myaccount/myapp/node_modules/mongodb/lib/core/connection/pool.js:460:61)
at Connection.emit (events.js:189:13)
at processMessage (/home/myaccount/myapp/node_modules/mongodb/lib/core/connection/connection.js:368:10)
at Socket.<anonymous> (/home/myaccount/myapp/node_modules/mongodb/lib/core/connection/connection.js:537:15)
at Socket.emit (events.js:189:13)
at addChunk (_stream_readable.js:284:12)
at readableAddChunk (_stream_readable.js:265:11)
at Socket.Readable.push (_stream_readable.js:220:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
ok: 0,
errmsg: 'command createIndexes requires authentication',
code: 13,
codeName: 'Unauthorized',
name: 'MongoError',
[Symbol(mongoErrorContextSymbol)]: {} }
nothing in the error is pointing toward something I created, it's only about the mongodb npm library. It also giving this error even if a delete every MongoDB connexion related code (but not the mongodb library load).
Do you have any idea how to fix this ?
Okay it's my fault. I had another connexion point that I didn't changed from my express sessions. It's fixed now.
It's just weird the error didn't point toward that module..

UnhandledPromiseRejectionWarning: error: password authentication failed for user " " after npm start

I am using node version 8 and when i do an npm start below errors are seen. I guess after routes are created below errors are seen. Here "techwedge3" is the username of my system. The application works correctly even with the below errors.
Even i am able to connect to my postgres db.
Any idea on how to resolve the issue?
[JobRoute::create] Creating route.
[InterviewRoute::create] Creating route.
[Creating AdminRoute::create] Creating route.
[TenantRoute::create] Creating route.
[CriteriaRoute::create] Creating route.
(node:12212) UnhandledPromiseRejectionWarning: error: password authentication failed for user "techwedge3"
at Connection.parseE (C:\Development\vilearnnew\vilearn_node\node_modules\pg-promise\node_modules\pg\lib\connection.js:546:11)
at Connection.parseMessage (C:\Development\vilearnnew\vilearn_node\node_modules\pg-promise\node_modules\pg\lib\connection.js:371:19)
at Socket.<anonymous> (C:\Development\vilearnnew\vilearn_node\node_modules\pg-promise\node_modules\pg\lib\connection.js:114:22)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)

MongoDB fails to respond on localhost but works for another node app

I'm working on a new node.js app on an old server I use for dev stuff.
Both apps have the mongo URL specified:
var mongoUri = 'mongodb://localhost/node';
but on startup, the old node.js app works fine, but the new one doesn't. The new one returns the following for node server.js
Error: unable to connect to database at mongodb://localhost/node
at NativeConnection.<anonymous> (/var/www/server/server.js:15:9)
at emitOne (events.js:115:13)
at NativeConnection.emit (events.js:210:7)
at /var/www/server/node_modules/mongoose/lib/connection.js:336:19
at args.push (/var/www/server/node_modules/mongodb/lib/utils.js:403:25)
at /var/www/server/node_modules/mongodb/lib/mongo_client.js:254:21
at connectCallback (/var/www/server/node_modules/mongodb/lib/mongo_client.js:933:5)
at /var/www/server/node_modules/mongodb/lib/mongo_client.js:782:11
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
Any thoughts or suggestions would be really appreciated. I've tried everything short of reinstalling mongo at this point :(

Resources