I am connecting to MongoDB Atlas and getting authentication fail error.
that is my connection string:
mongodb://user:<password>#mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-02-ixqtu.mongodb.net:27017/test?ssl=true&replicaSet=mongo-cluster-shard-0&authSource=admin&retryWrites=true
That is what I get:
------------------------------------------------
Mongoose connection "error" event fired with:
{ MongoError: authentication fail
at Function.MongoError.create (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/error.js:31:11)
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/replset.js:1245:38
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:760:7
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:736:20
at finish (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/auth/scram.js:168:16)
at handleEnd (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/auth/scram.js:178:7)
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/auth/scram.js:269:11
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:469:18
at process._tickCallback (internal/process/next_tick.js:61:11)
name: 'MongoError',
message: 'authentication fail',
errors:
[ { name: 'mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017',
err: [Error] },
{ name: 'mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017',
err: [Error] } ] }
Error: KeystoneJS (Keystone Demo) failed to start - Check that you are running `mongod` in a separate process.
at NativeConnection.<anonymous> (/mnt/c/WEB/keystone-md2/node_modules/keystone/lib/core/openDatabaseConnection.js:62:10)
at NativeConnection.emit (events.js:189:13)
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/lib/connection.js:824:17
at connectCallback (/mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:527:5)
at /mnt/c/WEB/keystone-md2/node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js:459:13
at process._tickCallback (internal/process/next_tick.js:61:11)
You have to put your user and password in your connection uri string
mongodb://***'your user':' here comes password '***#mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-02-ixqtu.mongodb.net:27017/test?ssl=true&replicaSet=mongo-cluster-shard-0&authSource=admin&retryWrites=true
e.g
mongodb://dbuser:dbpassword#mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-02-ixqtu.mongodb.net:27017/test?ssl=true&replicaSet=mongo-cluster-shard-0&authSource=admin&retryWrites=true
The problem is I was leaving <> in connection string. You have to remove those for authentication to work.
I was facing this issue too. But after an hour I came to know that I used the process.env variables for username and password. And also declared them in the .env file. But I forgot to configure dotenv package in my code.
So make sure you didn't make this kind of silly mistake.
For more info go through this documentation of node repositories.
https://www.npmjs.com/package/dotenv
I have a similar error but with connecting to the new Atlas database. Even though I have definitely setup the username and password correctly as stated here and in the documentation (obviously i replaced PASSWORD with my correct MLAB password:
var mongoURI = 'mongodb+srv://heroku_3kcdl3j9:PASSWORD#cluster-3kcdl3j9.auof1.mongodb.net/heroku_3kcdl3j9?retryWrites=true&w=majority';
I have migrated my database from MLAB to Atlas successfully set the correct Network access settings to 0.0.0.0 IP addresss. Setup the environment variable in Heroku. But still get this error:
{ MongoError: authentication fail
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/topologies/replset.js:1462:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:868:7
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:844:20
at finish (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:232:16)
at handleEnd (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:242:7)
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:351:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:531:18
at process._tickCallback (internal/process/next_tick.js:61:11)
name: 'MongoError',
message: 'authentication fail',
errors:
[ { name: 'cluster-3kcdl3j9-shard-00-01.auof1.mongodb.net:27017',
err: [MongoError] },
{ name: 'cluster-3kcdl3j9-shard-00-00.auof1.mongodb.net:27017',
err: [MongoError] },
{ name: 'cluster-3kcdl3j9-shard-00-02.auof1.mongodb.net:27017',
err: [MongoError] } ],
[Symbol(mongoErrorContextSymbol)]: {} }
(node:47015) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 's' of undefined
at Admin.buildInfo (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb/lib/admin.js:100:37)
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/index.js:95:13
at $initialConnection.then.err (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongoose/lib/connection.js:556:14)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:47015) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:47015) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:47015) UnhandledPromiseRejectionWarning: MongoError: authentication fail
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/topologies/replset.js:1462:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:868:7
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:844:20
at finish (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:232:16)
at handleEnd (/Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:242:7)
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/auth/scram.js:351:15
at /Users/bensmith/Downloads/DocumentsDirNew/Scraper and API/diveapi/node_modules/mongodb-core/lib/connection/pool.js:531:18
at process._tickCallback (internal/process/next_tick.js:61:11)
(node:47015) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
I had a similar error and in my case, the problem was I have added (whitelisted) a wrong IP address in "IP Access List" on "Security -> Network Access" page.
Related
I'm working with MongoDB to save data using transactions.But its giving the below error.
(node:29448) UnhandledPromiseRejectionWarning: MongooseError: Connection 0 was disconnected when calling `startSession`
at NativeConnection.startSession (D:\Rubix\rubixkyc\node_modules\mongoose\lib\connection.js:565:31)
at D:\Rubix\rubixkyc\server\util\route_utils.js:35:38
at new Promise (<anonymous>)
at saveKycData (D:\Rubix\rubixkyc\server\util\route_utils.js:32:12)
at D:\Rubix\rubixkyc\server\controllers\bulk_gst_verification_controller.js:48:19
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
at processPromiseRejections (internal/process/promises.js:247:11)
at processTicksAndRejections (internal/process/task_queues.js:96:32)
[RUBIX KYC] 27-12-2022 07:44:37.193 PM [info]: <server\controllers\bulk_gst_verification_controller.js:46> saving GST verification data ....
(node:29448) MongooseError: Connection 0 was disconnected when calling `startSession`
at NativeConnection.startSession (D:\Rubix\rubixkyc\node_modules\mongoose\lib\connection.js:565:31)
at D:\Rubix\rubixkyc\server\util\route_utils.js:35:38
at new Promise (<anonymous>)
at saveKycData (D:\Rubix\rubixkyc\server\util\route_utils.js:32:12)
at D:\Rubix\rubixkyc\server\controllers\bulk_gst_verification_controller.js:48:19
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(node:29448) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
at emitDeprecationWarning (internal/process/promises.js:180:11)
at processPromiseRejections (internal/process/promises.js:249:13)
at processTicksAndRejections (internal/process/task_queues.js:96:32)
Sharing the image of the code snippet.
Note:- This started happening after i started using worker pool for concurrency.
This save method i
const workerpool = require('workerpool');
Please help me with the issue
My NestJS backend needs to connect to the mongodb cloud, I followed the docs from here
The following error threw up in the terminal:
(node:6920) UnhandledPromiseRejectionWarning: MongoParseError: URI malformed
at new ConnectionString (D:\growth\quizbackend\quizbackend\node_modules\mongodb-connection-string-url\src\index.ts:113:13)
at Object.parseOptions (D:\growth\quizbackend\quizbackend\node_modules\mongodb\src\connection_string.ts:249:15)
at new MongoClient (D:\growth\quizbackend\quizbackend\node_modules\mongodb\src\mongo_client.ts:332:22)
at D:\growth\quizbackend\quizbackend\node_modules\mongoose\lib\connection.js:785:16
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (D:\growth\quizbackend\quizbackend\node_modules\mongoose\lib\connection.js:782:19)
at Mongoose.createConnection (D:\growth\quizbackend\quizbackend\node_modules\mongoose\lib\index.js:275:10)
at Function.<anonymous> (D:\growth\quizbackend\quizbackend\node_modules\#nestjs\mongoose\dist\mongoose-core.module.js:60:63)
at Generator.next (<anonymous>)
at D:\growth\quizbackend\quizbackend\node_modules\#nestjs\mongoose\dist\mongoose-core.module.js:20:71
(Use `node --trace-warnings ...` to show where the warning was created)
(node:6920) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:6920) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,
promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
My app module code:
import { Module } from '#nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UsersModule } from './users/users.module';
import {MongooseModule} from '#nestjs/mongoose'
#Module({
imports: [UsersModule,MongooseModule.forRoot('mongodb+srv://icfoajscijwq90j#cluster0.8rxa2.mongodb.net/nest-js-db?retryWrites=true&w=majority')],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
I doubled check my username and password but they are correct, is there any need for encoding them or why the error is throwing up any explanation would be appreciated.
Ensure that your username and password in the URI Connection string doesn't have any illegal characters.
If the username or password includes the following characters:
: / ? # [ ] #
those characters must be converted using percent encoding.
Based on their documentation: https://docs.mongodb.com/manual/reference/connection-string/
So basically I'm trying to send an announcement to specific channel using message.mentions.channels
ex !announce #announcements Today is a great day!
Error:
(node:5516) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'channels' of undefined
at Object.module.exports.execute (C:\Users\Zarko\Desktop\Stackoverflow\commands\Answers\announce.js:3:36)
at Client.<anonymous> (C:\Users\Zarko\Desktop\Stackoverflow\events\message.js:20:30)
at Client.emit (events.js:223:5)
at MessageCreateAction.handle (C:\Users\Zarko\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Zarko\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\Zarko\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
at WebSocketShard.onPacket (C:\Users\Zarko\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22)
at WebSocketShard.onMessage (C:\Users\Zarko\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
at WebSocket.onMessage (C:\Users\Zarko\node_modules\discord.js\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:223:5)
(node:5516) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:5516) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Code:
let channel = message.mentions.channels.first();
if (!channel) return
let announcement = args.slice(1).join(" ");
channel.send(announcement)
Error was how you passed in variables:
in one of your other command files you had:
execute(client, message, args) {
//this works
}
And in your announce command file you had:
execute(message, args){
console.log(message, args);
/* =>
Client {
...
}
Message {
...
}
*/
}
So in this instance, message is the actual client object, and args is the actual message object, so simply just fix your variable spots,
Your new execute function in announce.js
execute(client, message, args) {
//rest of code here
}
I need to save json object with other nested objects into my postgres db. The json I'm receiving from user's browser.
I'm using Postgres 11.5 on AWS RDS. On backend I'm using NodeJS (NestJS/TypeScript/TypeORM).
I tried to convert each item of array to string using JSON.stringigy() but anyway I'm receiving error UnhandledPromiseRejectionWarning: QueryFailedError: malformed array literal: "[{"name":"Oviedo, Asturias, Spain"},{"name":"Oviedo, Asturias, Spain"}]"
Array looks like this:
"waypoints": [
{
"name": "Oviedo, Asturias, Spain"
},
{
"name": "Oviedo, Asturias, Spain"
}
]
This is a field to store the array above
#Column({ type: 'jsonb', array: true })
waypoints: any[];
And I assign data like this:
event.waypoints = eventData.waypoints;
// also I tried to do like this
event.waypoints = JSON.stringify([{ text: 'Some text' }, { text: 'Some text 2' }]);
Right now I'm receiving error:
(node:12833) UnhandledPromiseRejectionWarning: QueryFailedError: malformed array literal: "[{"name":"Oviedo, Asturias, Spain"},{"name":"Oviedo, Asturias, Spain"}]"
at new QueryFailedError (/home/banha/Projects/train-time-server/node_modules/typeorm/error/QueryFailedError.js:11:28)
at Query.callback (/home/banha/Projects/train-time-server/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:176:38)
at Query.handleError (/home/banha/Projects/train-time-server/node_modules/pg/lib/query.js:142:17)
at Connection.connectedErrorMessageHandler (/home/banha/Projects/train-time-server/node_modules/pg/lib/client.js:211:17)
at Connection.emit (events.js:209:13)
at Connection.EventEmitter.emit (domain.js:476:20)
at Socket.<anonymous> (/home/banha/Projects/train-time-server/node_modules/pg/lib/connection.js:126:12)
at Socket.emit (events.js:209:13)
at Socket.EventEmitter.emit (domain.js:476:20)
at addChunk (_stream_readable.js:305:12)
(node:12833) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:12833) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
We have a custom express app that loads in the node.js parse server sdk. When we try to use a function call that requires the master key we keep getting errors for permission denied.
at /Users/gateway/Documents/lm/Website/lm-node/node_modules/parse/lib/node/RESTController.js:324:19
at processTicksAndRejections (internal/process/task_queues.js:86:5)
(node:61092) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
(node:61092) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
we initiate our parse server like this..
Parse.initialize(process.env.PARSE_STAGING_APP_ID, null, process.env.PARSE_STAGING_MASTER_KEY);
//Parse.Cloud.useMasterKey();
Parse.serverURL = process.env.PARSE_STAGING_SERVER_URL;
Parse.User.enableUnsafeCurrentUser();
module.exports = Parse
async function channelStatus(orgId) {
const Status = Parse.Object.extend("Status");
const query = new Parse.Query(Status);
query.equalTo("orgID", orgId);
try {
const results = await query.first({useMasterKey: true});
if(results) {
// do some stuff
results.save();
} else {
const StatusNew = Parse.Object.extend("Status");
const statusNew = new StatusNew();
// do some stuff
statusNew.save()
}
} catch (error) {
throw error;
}
}
if we enable Parse.Cloud.useMasterKey(); it works but this can be bad because it works for every function.. we want to make sure we are using masterKey on certain functions..
thoughts?
full error in visual studio.
(node:35145) UnhandledPromiseRejectionWarning: Error: Permission denied for action get on class Status.
at /Users/gateway/Documents/lmx/WebSite/lmx/node_modules/parse/lib/node/RESTController.js:324:19
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:35145) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
(node:35145) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
GET /test - - ms - -
Logs
Jul 29 13:08:29 lmx-stage app/web.1: error: Error generating response. ParseError {
Jul 29 13:08:29 lmx-stage app/web.1: code: 119,
Jul 29 13:08:29 lmx-stage app/web.1: message: 'Permission denied for action get on class Status.' } code=119, message=Permission denied for action get on class Status.
Jul 29 13:08:29 lmx-stage app/web.1: error: Permission denied for action get on class Status. code=119, message=Permission denied for action get on class Status.