nodejs/mongoose authentication issue on dotcloud - node.js

I'm using node.js with mongoose which cannot connect to the DB failing with authentication issue.
Using the connection env variable uri:
:mongodb://root:***#[appname]-[user]-db-0.azva.dotcloud.net:4518
And the result is:
{ [MongoError: auth fails] name: 'MongoError', errmsg: 'auth fails', ok: 0 }
Tried to build up own conn URI based on the environment variables like DOTCLOUD_DB_MONGODB_HOST etc, the URI is correct, passing to the env variable but the problem is still this based on the DB logs:
db.0 Sat Dec 29 00:31:08 [conn66] auth: couldn't find user root, admin.system.users
Could anyone help me how to resolve this missing user root?
Thank you in advance!!!
update: I logged in to mongodb console on the mongodb node via "use admin" and cannot authenticate with that username and password either. Nor create a new user and password. :(

Resolved.
The dotcloud system has provisioned the db instance badly somehow.
Creating a new app, everything is working fine.

Related

firebase 9 permission denide from localhost

i'm using Firebase version 9 (MODULAR) as database for a web application in nodejs v18.
When i try to access data from localhost i get the error below, but from an heroku deployment works like a charm.
[2022-06-26T07:32:22.447Z] #firebase/firestore: Firestore (9.8.4): Connection GRPC stream error. Code: 7 Message: 7 PERMISSION_DENIED: Permission denied on resource project "my_project",.
[2022-06-26T07:32:22.447Z] #firebase/firestore: Firestore (9.8.4): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=permission-denied]: 7 PERMISSION_DENIED: Permission denied on resource project "my_project",.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
[2022-06-26T07:32:22.466Z] #firebase/firestore: Firestore (9.8.4): Connection GRPC stream error. Code: 7 Message: 7 PERMISSION_DENIED: Permission denied on resource project "my_project",.
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^
[FirebaseError: Failed to get document because the client is offline.] {
code: 'unavailable',
customData: undefined,
toString: [Function (anonymous)]
}
Node.js v18.0.0
For context:
the web app its an internal tool so i do my own authentication server-side and then the app makes some checks on some data on the firestore db. So basically who makes the queries its the app,not the user. This makes me thing that i should use a service account with firestore-admin api.
The problem is that the provided code snippet from the docs,does not work for me..
var admin = require("firebase-admin");
var serviceAccount = require("path/to/serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
And i already changed the access rule to be the horribly unsecure one:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
Any idea on what i should do? Or maybe why it doesnt work on local development?
Since the documentation it an incomplete maze of stuff i am probably missing something..
Thanks to anyone that can help! (at least to understand why)
As the GitHub link suggests, the issue might be due to useFetchStreams being enabled by default, in the new modular build (v9).
Hence, modify your code accordingly:
import {initializeFirestore} from 'firebase/firestore'
const db = initializeFirestore(firebaseApp, {useFetchStreams: false})
Also, the error might arouse not because the android device or emulator you are debugging is offline but because the "databaseURL" setting was missing in the part that defines the Firebase configuration object. I think that the same error might occur if the setting is incorrect.
Also, I suggest you have a look at this Stackoverflow case, which talks in detail about all the probable reasons behind the ‘Client is offline’ issue.
However, if the above solution does not, suggest you enable debug logging by calling setLogLevel.
firebase.firestore.setLogLevel('debug');

Connection sasl conversation error(authentication error) while using mongoexport

I am trying to export data from a mongodb cluster to my computer, using my URI connection string, but am getting the error: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-S HA-1": (AtlasError) bad auth Authentication failed
This is the command I am using:
mongoexport --uri="mongodb+srv://yash_verma:<******>#jspsych-eymdu.mongodb.net/test?retryWrites=true&w=majority" --collection=entries --out=entries.csv
Could anyone tell me what it is that I am doing wrong? I am sure I am using the correct password.
I am also fairly new to programming and have tried to look online for a solution, but haven't found one yet.
Any help would be greatly appreciated.
Thanks,
Yash.
Your connection string looks fine, but make sure to remove the angle brackets (<>) around <password>, like so:
mongoexport --uri="mongodb+srv://yash_verma:******#jspsych-eymdu.mongodb.net/test?retryWrites=true&w=majority" --collection=entries --out=entries.csv
…where ****** is the database password (not the account password!) of the database user yash_verma.
Duplicate answer

dbAdmin user can not execute list command on MongoDB 3

I created a new Database called meanapp.and I add a user meanUser for readWrite role.
When I connect to the mongo DB via mongoose it connects but I got Error as
{ MongoError: not authorized on meanapp to execute command { listIndexes:"jobs", cursor:{}}
So , I tried to grant dbAdmin role to meanUser by executing
db.grantRolesToUser('meanUser',[{role:"dbAdmin", db: "meanapp" }] )
And tried restarting mongo deamon.
And db.getUser('meanUser') shows the dbAdmin role for that user.
Still same error.
Could any one faced this issue or I am missing something?
I refered mongo docs also I could get an idea of this issue.
Thanks for your effort.

What does authSource means in mongo database url?

i am trying to connect to my mongo database with following connection string
var Mongo_url = 'mongodb://MyUSer:tech#localhost:27017/chatme?authSource=admin';
I am getting error as
assertionError: null == { [MongoError: Authentication failed.]
name: 'MongoError',
message: 'Authentication failed.',
ok: 0,
code: 18,
Could anyone please clear this "authSource=admin" thing to me.
This is the name of the database that has the collection with the user credentials.
https://docs.mongodb.com/manual/reference/connection-string/#connections-connection-options
This is where the usernames and passwords are set up.
I spent a few hours today trying to solve this problem and unfortunately, this SO post didn't appear in my searches. That was too bad because it's the post with the best answer to the problem.
I hope to help the next person by adding the error message I got.
I'm setting up the connection inside a Docker container that is spun up via a docker-compose yaml file. The user name and password are passed into docker-compose from a .env file.
Connection URI that works
mongodb://aUser:aPassword#mevn-app-mongo:27017/myDb?authSource=admin
Error:
SASL SCRAM-SHA-1 authentication failed for aUser on myDb from client 172.25.0.3:37352 ; UserNotFound: Could not find user aUser#myDb

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