/Examples/JavaScript/Nodejs/With MongoDB
Documentation

With MongoDB

Buildfunctions
MongoDB
Data API
Serverless
Backend

Overview:

Note: All of the environment variables we will be using to build this project can be accessible from the MongoDB Atlas dashboard.

We will reference these values as

MONGODB_URL

MONGODB_DATASOURCE

MONGODB_API_KEY


Sign into MongoDB Atlas and create a database cluster. Make sure to select a `Cluster Name`. We will be using this as our

MONGODB_DATASOURCE
.

If you have already created a cluster you can verify it's name here.


For the sake of this demo we have provided mock data into our database with the

load sample data
feature. You should see this available once you click the menu button here.

Next you will want to click the 'Data API' link from the sidebar on the left-hand side of the page.

From there click settings and verify that you have enabled the Data API.


You should also see the endpoint URL we will be using as our

MONGODB_URL
. It will look something like this:


Lastly, you will want to create an API key. You should be able to do that from the Data API page as well. This will be our

MONGODB_API_KEY

Remember to enter your environment variables into the Buildfunctions Console page where they will be encrypted at REST.

Let's take a look at the example code

Example:

Loading editor…

Response:

Once you create and configure a MongoDB database cluster, andbuild and deploy this function with your environment variables swapped, then any request to the corresponding endpoint domain would result in the following response

 The Land Beyond the Sunset
Was this helpful?