Connecting to MongoDB

I’ve been trying to connect to MongoDB with my server credentials but I can’t seem to get the connection.

Hostname: “https://xxx.usemoralis.com/
Port: 2053
DB: “server”
username: Dashboard Username
password: Dashboard Password

Is connecting the db from outside restricted?

Hi @cellanrust,

Could you elaborate on what you were trying to do? Perhaps the steps taken and final issue at hand with config code and moralis server url?

It will help us evaluate your problem more efficiently.

Thanks.

Hey, sorry for the late reply!

Some part of my program is written in Rust and I need to get information from the database.

I was trying to connect the database from a Rust program and I couldn’t get connection so I checked out the mongoDB docs and downloaded mongosh to see if I can connect from there but the connection still fails.

When you are using Moralis, you need not setup MongoDB manually nor do you have to provide connections to your DB. Moralis comes with an inbuilt Mongo DB that you can query and edit as you please.

You can start learning how to use the database from here – https://docs.moralis.io/objects

Hope this helps. :man_mechanic:

That’s great and all but as far as I know you can only query from Javascript which doesn’t help my situation

Yes, Moralis is mainly a Javascript SDK. There will be more language supports with production ready code very soon. We are right now focusing on infrastructure thus the later release. :slight_smile:

1 Like

Is it possible to connect with a mongodb client such as Compass or noSqlBooster to the database?

I didn’t try those clients, but it is possible to connect from a Python script. You’ll have to use only IP and PORT without username and password, and you’ll have to whitelist your IP in your Moralis server settings.

Hi could you please provide an example of this? I tried to do so but always get: pymongo.errors.ServerSelectionTimeoutError: xxxIPxxx:xxxPORTxxx: [WinError 10054] An existing connection was forcibly closed by the remote host, Timeout: 30s

Thank you so much, one last thing:

MONGO_HOST = “asfasdf.moralis.io

what would I replace asfasdf with?

The MongoDbIP? or the link to my dashboard? or my server URL?

very much appreciated

you put there the IP that you find in your admin interface for mongo db, in same place where you find the port

If I’d like to connect via mongodb in javascript (ignoring the moralis API), what would be the username or password?

Thanks!

no username or password, you’ll have to whitelist your IP in admin interface

Can you show how the url would look like, can I just leave out username and password?

Can i whitelist a domain if I have a changing IP address?

you can not whitelist a domain, only IPs

What is the correct way for implementing server side rendering database connections under varying IP addresses in production settings?

you could use a proxy that has a static IP, or you could use Moralis SDK to make queries in db and not connecting directly to DB (you can use master key server side)

1 Like

Thanks for you fast feedback! Will give that a try :+1:

Works like a charm with the Moralis SDK. Great work!

1 Like