Configuring Database connectors - NoSQL (MongoDB)

You have seen how you can add Relational Databases like MySQL, Microsoft SQL, PostgreSQL to your apps. Studio also offers the connector to connect to different NoSQL DB such as MongoDB.
Let us consider MongoDB which is a document-based database here. You can use the connector to carry out various operations including querying and inserting and updating details.

To use the MongoDB datasets you simply need to add the MongoDB connector, configure the connector using the database details, provide the necessary values, and test it before you validate. Once your configuration is complete you can add a query as per your requirement.

Let us first have a quick look at the video here to understand how to configure the MongoDB connector.

Adding a MongoDB Connector

To add a MongoDB connectors, under Studio > Connectors, click (+) Connector. Select the MongoDB and click Add.

Studio allows you to connect to both managed and self-hosted MongoDB databases including MongoDB Atlas and AWS DocumentDB. Studio supports MongoDB’s standard connection format (mongo://) as well as the new seed list connection format (mongodb+srv://). So if you are using a managed offering such as MongoDB Atlas, the seed list connection format may be preferred. For more details, you can refer to this MongoDB Documentation here.

Configure MongoDB connector

You first need to provide the details of your Connector. Enter a Connector name and then proceed to add the connection string.

The most important part of the process is to provide connection configuration details.

You can provide the Connection string or provide the respective parameters.

In this case, note that to connect to the MongoDB database/dataset you would need a few parameters or fields. Here, we will be taking a sample public MySQL database sample_airbnb.

The connection parameters that are required are Host and database name. You also can enter the respective username, password, and port number and click Submit.

You can also enable further action to Connect using SSL, Enable SSH Tunneling, and Whitelisting IP.

Once these configurations are done, you need to Test the request and connection. If the authentication is successful you would get the response accordingly. Click Save.

Add query to the Database connector

The DB connector is now added to the Custom Database connectors section. You would have the Add query to the database.

First, give a name with which the query would be available for use. The actions supported by MongoDB are listed out. Select the action represented by the name. You will find parameters depending upon the action. For example, if your action is Find the parameters would be Filter, projection, sort, limit, and skip. If you choose InsertOne as action, the parameter would change to Insert as Key: Value string. Once you have assigned the necessary values, you can Run the query. The response can be seen as per the parameters given.

You can also add dynamic values using the Variables. To use a variable inside a query, you simply need to put it into double Curly brackets. The Test value that you entered would be considered when you are running this query here for testing.

You can now view the queries that you saved for use in your apps later under your specific connector.

Now that you want to make use of these Database connectors in your Apps, Under your app, click Connectors > Connected. Your configured app is listed out there.

find connector

In order to use the connector in a control. you can go to its data bind section as well as you can use the action property of the control. For both the methods, the steps are similar. Select MongoDB from the list and select the connector query that would be used to fetch data and click Continue. You can also view the SQL query being used using Show query. If you want to hide the query for some reason, click Hide Query. Beyond the configured queries, if you need a few more queries you can use the Add Query option.

Now your account needs to be authenticated. So select your Connected Account and click Continue. You can now configure the connector’s fields. Add the input values.

You can provide conditions to make use of this query under certain conditions by providing the details in the When to Execute section.

Next, simply do a refresh response and select the select the columns to bind in the control from the response of the exected query. After that click Test & Finish.

Now whenever you run the app, you can see the results based on the input values.

Using the MongoDB Connector is similar to using the sheets with your apps. You can make use of the different Queries to fetch data as well bind data such that you can undertake the insert, update, delete actions as well.

You can refer to this link here to understand how to use the API services.