MongoDart Authentication format issue - mongodb

I'm trying to use MongoDart with Dart as backend. It was working fine till I shifted to a dedicated instance instead of serverless. This is the issue I see:
MongoDartError (MongoDart Error: Authentication failed.)
I'm using dedicated cluster with 3 nodes, deployment name is com-new and db name is main:
var db = await Db.create('mongodb+srv://com-admin:*****#com-new.iv00u.mongodb.net/main');
await db.open(); // MongoDart Error
This is working correctly on mongodb compass and mongoose, but on mongodart it gives the error auth failed. I also tried this:
mongodb+srv://com-admin:*****#com-new.iv00u.mongodb.net/main?authSource=admin
& this
mongodb+srv://com-admin:*****#com-new.iv00u.mongodb.net/main/?authSource=admin
This exact command is working with the old serverless db instance, but I want to use changeStreams which is not available unless we use a dedicated or shared cluster.

Related

connect mongoose in nextjs middleware

I'm trying to connect next.js app to mongodb via mongoose in _middeware file(./pages/_middleware.ts )
But I get this error on incoming requests:
error - (middleware)\node_modules\mongoose\dist\browser.umd.js (1242:0) #
ReferenceError: regeneratorRuntime is not defined
How can I fix it?
+1 I have the same issue when trying to use in the middleware the instance created for mongoose so I don't have to connect it every time I make a request... but it seems this might not be supported yet.
It appears that it is not possible to use node api calls inside of NextJS middleware as this middleware is executed in the Edge runtime. Mongoose is a Node.js api, hence why is doesn't work.
Edge and Node.js Runtimes

PERMISSION_DENIED: Missing or insufficient permissions... and I change nothing

I know this question has been asked a few times, but I couldn't find any working answer.
I'm using Google App Engine and Firestore (Database location: eur3 - europe-west).
A few days ago, my simple app was working like a charm and more precisely Firestore was working.
I could test/use it locally through nodemon or online (when deployed).
Since this morning, and I change nothing, it doesn't work anymore locally.
I can't access my DB locally anymore, but I can when deployed to GAE.
Locally I got this error and this is a DB access issue:
PERMISSION_DENIED: Missing or insufficient permissions. {"code":7,"details":"Missing or insufficient permissions.","metadata":{}}
My code to access DB has always been as simple as:
// service/firestore.js
const Firestore = require("#google-cloud/firestore");
const db = new Firestore();
module.exports.db = db;
Do you have any clue why I can't write/read locally to Firestore this morning?
(BTW I've never modified security rules and it has always been working).
Thanks

How can I connect to an Atlas cluster with the SRV connection string format using ReactiveMongo?

I have a play scala app and i have an atlas cluster which i am trying to connect. According to the ReactiveMongo this is possible. I can add my connection string gotten from Atlas to my app via
mongodb.uri
In my application.conf file. I have tried everything based on the instructions from reactivemongo and atlas db but i am still unable to connect to the cluster. using my mongoshell however, i am able to connect and have access to my db but it simply refuses to connect via my app.
Mongo simply returns an error "MongoError['No primary node is available! (Supervisor-13/Connection-14)']" } and logs a warning in my console Some options were ignored because they are not supported (yet): w, retryWrites. I am using scala version 2.12 and reactivemongo 0.12.6 with play 2.6.
My connection string is mongodb+srv://<username>:<password>#my-cluster.abo25.mongodb.net/my-db?retryWrites=true&w=majority
Any info or help would be greatly appreciated.
Solved my problem. It turns out the +srv string format works seamlessly from reactivemongo version 0.17 and i was initially on 0.16. After i upgraded (and also upgraded my code), i was able to connect to my cluster. I also found out one of the user credentials i was using was wrong so that plus the upgrade got me up and running.

Authentication DB setting not working using mongoDB URI configuration

I am triyng to connect pyeve with a MongoDB Atlas replica set (https://cloud.mongodb.com/). I've connected successfully DB management tools from the same host, to make sure the deployment is working OK.
One particularity is that using Atlas, all users must authenticate against auth database, I cannot put my users in the application database, so I need to set authSource in MONGO_URI.
Now, when defining the MONGO_URI for the replica set, in settings.py, like this:
MONGO_URI = mongodb://<USER>:<PASS>#my-shard-00-00-tlati.mongodb.net:27017,my-shard-00-01-tlati.mongodb.net:27017,my-shard-00-02-tlati.mongodb.net:27017/<MY_DB>?ssl=true&replicaSet=my-shard-0&authSource=admin
The authSource=admin parameter seems to be ignored, (I've checked debugging pymongo's auth and the authentication source used is None).
MONGO_AUTH_SOURCE could be used to set the authorization database, but it has no effect since MONGO_URI is used in preference of the other configuration variables, according to eve's documentation.
Is this an issue or am I doing it wrong?
Found out that the problem was that I was using version 0.4.1 for flask-pymongo. Updating it to version 0.5.1 fixed the problem.

Azure Function with Cosmos MongoDB integration not saving

I have setup a Azure Function with a Azure Cosmos DB(document) output. The cosmos database is configured to be a MongoDB.
And added the following simple code to try and add a new document:
module.exports = function (context, eventHubMessages) {
context.bindings.document = {
text : "Test data"
}
context.done();
};
When i test run i get success, but when i try to open the the collection using Studio 3T i get:
Query failed with error code 1 and error message 'Unknown server error occurred when processing this request.'
When i use the same code to write to a DocumentDB i get success and i can view data in Azure. Do you need to use a different API to save data to mongoDB?
The DocumentDB output binding is using the DocumentDB API to connect and save information in the database. But your database (from what you are saying) is using the MongoDB API, they are different APIs (links point to the docs).
As you surely know, MongoDB has some requirements (like the existence of an "_id" attribute) that are covered when you connect to the database from a MongoDB client (either an SDK or a third-party client), but since you are communicating through the DocumentDB API, it's probably failing to fulfill those requirements.
You might want to try and use the Mongo driver in the function to connect to your Cosmos DB database through the MongoDB API.