Building a LoopBack MongoDB API
Key Points
- Created a new LoopBack project named “customers” using the `apic loopback` CLI and added the MongoDB connector (`loopback-connector-mongodb`) to enable database communication.
- Configured a MongoDB data source through the API Designer, supplying host and port details and testing the connection.
- Defined a “Customer” model linked to the MongoDB data source, added required properties (first name, last name, zip code) with appropriate data types, and enabled automatic REST API generation.
- Launched the application locally with the Microgateway, used the API Explorer to POST new customer records and GET the list of stored customers, verifying the end‑to‑end setup.
- Demonstrated the basic LoopBack workflow for creating data sources, models, and RESTful APIs backed by MongoDB.
Full Transcript
# Building a LoopBack MongoDB API **Source:** [https://www.youtube.com/watch?v=YHqdJAiw6cc](https://www.youtube.com/watch?v=YHqdJAiw6cc) **Duration:** 00:03:07 ## Summary - Created a new LoopBack project named “customers” using the `apic loopback` CLI and added the MongoDB connector (`loopback-connector-mongodb`) to enable database communication. - Configured a MongoDB data source through the API Designer, supplying host and port details and testing the connection. - Defined a “Customer” model linked to the MongoDB data source, added required properties (first name, last name, zip code) with appropriate data types, and enabled automatic REST API generation. - Launched the application locally with the Microgateway, used the API Explorer to POST new customer records and GET the list of stored customers, verifying the end‑to‑end setup. - Demonstrated the basic LoopBack workflow for creating data sources, models, and RESTful APIs backed by MongoDB. ## Sections - [00:00:00](https://www.youtube.com/watch?v=YHqdJAiw6cc&t=0s) **Creating LoopBack API with MongoDB** - The speaker walks through setting up a LoopBack project, installing the MongoDB connector, configuring a datasource, and defining a Customer model with a generated REST API. ## Full Transcript
in this video we'll create a new
loopback project to record customer
information to mongodb first run apic
loopback to create an application and
enter a name when prompted in this demo
I'll name it customers select the
default options but when asked about the
kind of application choose an empty
server change into the customer
directory and run npm install loopb
back- connector DM M OD db-- saave to
install and save the connector which
will allow our application to speak with
mongodb after we set up our data source
next run apic edit to open the API
designer in your browser click log in
with Blu miix then use your Blu miix
credentials to log in now let's create a
data source which will configure our
connection to the database click the
data sources tab then the plus button
and enter a meaningful name name for the
data source I'm naming mine mongodb in
the next form fill in the necessary
configuration information such as the
host and Port of your database
then click the diset in the upper right
to save and test the connection to the
data source we just defined let's go
create a model now click models and then
the plus button to add a new model I'll
name this model customer since we'll use
it to store customer
information set the data source to the
name of the data source created earlier
in my case mongodb the public check boox
indicates to our application that we
would like it to create a rest API for
this model click the plus button in the
lower right to add a property to your
model I'll add first name last name and
zip code I want to be sure my
application always includes these
properties so I'll check the required
box next to all of them also notice that
I can select the type for for the
property this will ensure zip code will
always be a number and the names will
always be strings click the diset in the
upper right to save let's try out our
new API click the play arrow in the
lower left this starts a local instance
of your application and micro Gateway so
that you can try out your application
locally now let's investigate our new
API hit explore then we'll use the post
customers API to create new customer
entries click the generate Link in the
parameters field to generate a random
entry based on the model we made I can
click call operation to save the model
to the
database I'll create one more entry and
edit the ZIP code
field I can then go to get customers API
to get a list of all the customers in my
database that concludes our tutorial of
the basics of loopback data sources
thanks for watching