Connecting to MongoDB


#1

This is a quick guide on how to setup database connection to MongoDB using both the hosted and locally installed instances of your Dreamfactory Services Platform (DSP).

First things first: make sure we have a Mongo database to work with! In this example, I will refer to the MongoHQ site where I setup my own test DB. At this point, I will assume that we have a Mongo Account. Now, we just need to make sure that we have an actual database created. In my case, this DB is called “MongoDB.”

Now, a few things that are key to creating our service from the DSP to our Mongo DB: username/password and database name. Again, in my case, these would be as follows:

DB_name: “TestDB”

User: "testuser"
Password: “testpass”

We also need to get our Mongo “Connection String.” If we navigate to the admin overview within Mongo, we should find the connection string in the following format:

mongodb://:@oceanic.mongohq.com:10080/TestDB

Now that we know these things, let’s proceed back to our DSP and go into the admin console.

Once there, let’s go to the Services tab on the left side of our console. Go ahead and open this up.

Within the Services page, we can “Create a New Service” - which is located at the top right of our screen.

We are now coming to the home stretch!

Now, we just have to fill in some fields to create our service within the DSP. Have a look at my screenshot to see exactly how I created my MongoDB service!

The API name field here is very important, as it will be the reference key for anytime you want to call this service within your application.

The Name field is the display name. So, this is the name we see within our DSP.

The rest of the info should come directly from MongoHQ!

Simply copy/paste your connection string and input the details on your DBname, username, and password.

Now, we can test to make sure it works.

One quick way to test is to click the “Roles” tab on the left side. It will give you an error if any service fails to connect. Otherwise we can test using the Live API!

Thanks! We should all be connected to Mongo now!

Feel free to respond with any questions, thanks again.

  • Mark