LoopBack — MongoDB ToDo

Cris Ferreira Pires
2 min readApr 14, 2021
Loopback 4

We will be making an API that will use MongoDB for its database.

The ids are going to be tricky on this one. Fear not as long as you follow closely things will work.

After creating an api with loop back. If you still have doubts on how to do that, follow my previous story, we need to install a npm package to connect loopback and mongo db.

npm i -s loopback-connector-mongodb

As always we start with the model:

lb4 model todo

todo model setup

Make sure that the first property is “id” and that it isn’t automatically generated nor required, also keep it as a string.

Then we go for the datasource:

lb4 datasource todo

todo datasource setup

Now the repository:

lb4 repository todo

Finally the controller:

lb4 controller todo

todo controller setup

And now we are ready to run the API.

Now try testing it on the swagger ui found at: localhost:3000/explorer

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response