2021 Call for Code Awards: Live from New York, with SNL’s Colin Jost! Learn more

Use Mongoose and MongoDB to serve app data

Summary

Working with MongoDB data can be time-consuming and labor-intensive, requiring you to write extensive validation and business logic. Mongoose, an Object Data Modeling library, makes it easy for you to manage data relationships and provides schema validation for MongoDB objects. In this code pattern, you’ll learn how to use Mongoose to connect to your MongoDB database so you can read and update documents.

Description

Mongoose provides an easy way to model your data with MongoDB. It connects to a MongoDB database so that you can configure your Node.js app to create, read, update, or delete documents in the database. The Express framework helps you make RESTful APIs quickly and easily for your database operations.

This code pattern shows you how to conveniently configure a map server application to use a database for data storage. The application will be deployed in a Kubernetes platform.

This pattern is part of a larger application. That application is a map server where data such as booths, events, and beacons (for generating a heat map of the event) are stored. The map server will be used as a back end for a user-facing dashboard. The dashboard, using the data from the configured APIs of our server, will visualize that data and show a map or floor plan to users. This map server will also be used to generate an indoor map in an iOS app.

When you have completed this code pattern, you will understand how to:

  • Implement Mongoose with NodeJS
  • Create RESTful APIs with database operations

If you’re ready to harness the flexibility and convenience of Mongoose in your apps, this is your starting point.

Flow

flow

  1. The user sets up a MongoDB database. Compose for MongoDB is used in this pattern.
  2. The user adds mock data that matches the schema of the models set in the application.
  3. The user interacts with the deployed app through its APIs. The user can view an indoor map in SVG or PDF format.

Instructions

You will find the detailed steps for this pattern in the README. Those steps will show you how to:

  1. Clone the repo.
  2. Create Compose for MongoDB service with IBM Cloud.
  3. Build your images.
  4. Configure deployment files.
  5. Deploy the application.
  6. Generate mock data.
  7. Perform API requests.
Legend