Invalid connection mongo db url on prisma - nestjs

i'm trying to connect into a database and the database url that it's in the .env file is that DATABASE_URL="mongodb//root:Bambam&xx12#localhost:27017/dataviewer" but it's allways saying that it's an invalid url, can anybody say what is wrong with my url connection?

The MongoDB database connector requires a replica set deployment as described in this prerequisites.
You can follow this guide to configure replica set deployment in your local MongoDB instance.
The easiest way would be to use MongoDB Atlas as they have a replica set pre-configured.

Related

Hosting and connecting to a google cloud sql databse

I'm currently building a website that I would like to privately host so it can only be used internally. My goal is to store file uploads into a google cloud bucket then document certain things into a cloud sql db for filtering later on.
I've been able to store and pull my files from a bucket and I was also able to set up my database in cloud sql however I'm not totally sure how to send SQL query's to my database from my website. I've tried going through the documentation but I'm a bit lost as to what I need. So if anyone knows what I should be looking at that would be a lot of help. Anything like a guide on the google documentation, because I'm not sure which I need to follow or anything.
Additional information
Currently my website is hosted locally because I haven't decided on a
website hosting service yet any recommendations would be helpful.
I was using a postgres database as practice for creating endpoints and developing my database
structure.
I am using a PERN stack so postgres, express, react and node.js
If there's anything else you would like specified I'm more then happy to provide any additional information.
Update:
I was able to connect my postgres db to cloudsql. I would explain how but this video does a great job of it.
How to connect psql db to cloud sql
However I'm running into an issue when I try to connect using an SSL connection. I have the files my only issue is I don't know where to store these files.
The general recommendation is to use the Cloud SQL Auth Proxy to connect to your Cloud SQL instance.
Basically you'd run the proxy wherever you're running your webapp and then have your webapp connect to the proxy as if it were a local database.
You'll start the proxy like this:
./cloudsql_auth_proxy -instances=<INSTANCE_CONNCECTION_NAME>=tcp:5432
That will start a listener on 5432 on localhost that you can connect your webapp to.
Alternatively, you could use Authorized Networks to allow-list the IP address of the machine where your app runs.
Check out the docs here: https://cloud.google.com/sql/docs/postgres/connect-overview.

Express.js application deployed to azure won't connect to mongoDB in cloud

I deployed an express REST API using visual studio azure extension. It only consists of endpoints that serves JSON data. I have a few endpoints that it only serves and error message, those are working just fine, so the express application is working correctly but when I reach to an endpoint that requires to read from MongoDB, in visual studio, inside the streaming logs it prompts this:
Error:
(node:68) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [cluster0-shard-00-02-cia4k.mongodb.net:27017] on first connect [MongoNetworkError: connection 4 to cluster0-shard-00-02-cia4k.mongodb.net:27017 closed
So as you can see it says it having a problem connecting, and I don't know what failed to connect to the server, "connection 4" means in this case.
I'm trying to connect an express application to MongoDB in the cloud. I'm using MongoDB Compass to visualize the data, and it doesn't have a problem connecting. These are the things that I made sure were correct.
Network Access in MongoDB: Azure IP is registered in MongoDB (I found it in the "Custom Domain" tab in azure).
Node.js has the correct Mongo address: mongodb+srv://<MyUsername>:<MyPassword>#cluster0-cia4k.mongodb.net/<DatabaseName>.
I add this as a parameter at the end to the mongo address mongodb+srv://...?authSource=admin.
I'm not trying to access a local MongoDB in the VM in Azure.
I already look at this StackOverflow thread but I couldn't find something that helped me. Most of the problems in that post were locally in their computers.
Please help me.
I've found the solution, So I wasn't wrong about one of the steps that I made but it required an extra setup. Basically the problem was this:
Network Access in MongoDB: Azure IP is registered in MongoDB (I found it in the "Custom Domain" tab in azure).
It turns out that Microsoft Azure has multiple outbound IP Addresses. You can find them under the (Setting > Properties) > Outbound IP addresses. Put them all in MongoDB Atlas and that fixed my issue.

Connecting to Mongodb atlas from Node.js docker services

So I am learning node.js,docker and mongodb.And I have a few doubts.
I have three tasks of a service(replicas) (node.js in docker services).The service is supposed to access a mongodb database.I have two options:
Use atlas-this sounds simple to me as I am a beginner.
Use mongodb containers-Which I believe could be a little more work.
So the question is if I use MongoDB atlas and connect to the database hosted on atlas is the transfer of data between node.js and atlas secure by default?what should be done to "secure" the transfer of data between the node.js container service and the Mongodb atlas?
If I choose the second option above should all three replicas/tasks communicate with only ONE mongodb container?
is the transfer of data between node.js and atlas secure by default?
Without knowing your application environment, I can't comment about security on your side of the network.
However for MongoDB Atlas, it's using TLS/SSL and authentication (SCRAM) enabled by default (and cannot be disabled).
Traffic from clients to Atlas is authenticated and encrypted in-transit, and traffic
between the customer’s internally managed MongoDB
nodes is also authenticated and encrypted in-transit using
TLS/SSL.
Also depending on which cloud provider you would choose in Atlas (AWS, GCP, or Azure) they each provides different encryption at rest features (transparent disk encryption).
Please note that there are other security features provided by MongoDB Atlas, i.e. IP Whitelisting. See also MongoDB Atlas: Security Features and Setup and MongoDB Atlas Security Controls.
If I choose the second option above should all three replicas/tasks communicate with only ONE mongodb container?
I'm not sure I understand this question. The purpose of having a replica set is to provide High Availability (in the case of a primary failover, the other will automatically take over). Having all three nodes of replica set deployed into a single Docker container will defeat this purpose.

Connection Node app with MongoDB hosted in a Droplet

I am now trying to host my Angular, Node, MongoDB app on DigitalOcean. I have succesfully set up the two Droplets, one for Node Backend and one for MongoDB Database. Until now I was using a local link to connect to local database like the following link mongodb://localhost:27017/creditApp .
How do I connect my Node app hosted in Droplet to the MongoDB hosted in another Droplet? The database has admin password set up, also has allowed the IP address from my backend in the ufw list. I assume it needs a config object with admin name, password, ssh key .pub file etc and attach that object while trying to connect it, but I am not quite sure how to do it. How do I get this done?
Any help will be highly appreciated, thanks in advance.

Connecting to Mongodb Amazon EC2 instance programmatically in Nodejs

I am making a NodeJS webapp. I would like to deploy the app using Amazon's elastic beanstalk and I would like to use MongoDB as the database. Right now my understanding of a solution is to:
Set up a MongoDB instance on an Amazon EC2 instance (I've already done this)
Connect to this database programmatically in server.js to read and write to the database
Does this solution make sense? If so, how do I connect to the EC2 MongoDB instance programmatically?
I've found the official MongoDB package for node:https://www.npmjs.com/package/mongodb
but the documentation only mentions connecting to a local instance of MongoDB:
// Connection URL
var url = 'mongodb://localhost:27017/myproject';
// Use connect method to connect to the Server
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
console.log("Connected correctly to server");
db.close();
});
Current I am able to ssh into my EC2 MongoDB instance but I don't understand how to take the next step and connect to it programmatically.
When I ssh into the EC2 MongoDB instance, I need to provide a .pem key file, do I need to do something similar when I connect programmatically?
As per your use case your Mongodb is local on a EC2 instance. So when you connect to Mongodb you will have to SSH using a pem key to EC2 instance in order to connect to the Mongodb. If you want to avoid using pem key each time, you can create a SSH user which can SSH to instance using UN and password.
This is helpful guide to achieve it:
https://coderwall.com/p/j5nk9w/access-ec2-linux-box-over-ssh-without-pem-file
Or another way is connecting using the SSH key.
No, you don't need a .pem key for connecting to MongoDB instance.
Make sure your Ec2 instance has a public domain or IP. This IP can be used in place of localhost in your node DB configuration.
The mongo server should be running on the instance. Check mongo shell to confirm.
Create a VPC for better management of instance and define security group with required ports.
Use security credentials in your database configuration file.
I would suggest to always have a private IP for database instances and the instance on which your HTTP server is running should have public IP which is mapped with DNS provider. Open minimum ports on DB server mainly :27017 which makes it secure. Both the instances should be inside once VPC since private IP's are only accessible here.

Resources