Reader small image

You're reading from  MongoDB Fundamentals

Product typeBook
Published inDec 2020
PublisherPackt
ISBN-139781839210648
Edition1st Edition
Tools
Concepts
Right arrow
Authors (4):
Amit Phaltankar
Amit Phaltankar
author image
Amit Phaltankar

Amit Phaltankar is a software developer and a blogger experienced in building lightweight and efficient software components. He specializes in wiring web-based applications and handling large-scale data sets using traditional SQL, NoSQL, and big data technologies. He is experienced in many technology stacks and loves learning and adapting to newer technology trends. Amit is passionate about improving his skill set and loves guiding and grooming his peers and contributing to blogs. He is also an author of MongoDB Fundamentals.
Read more about Amit Phaltankar

Juned Ahsan
Juned Ahsan
author image
Juned Ahsan

Juned Ahsan is a software professional with more than 14 years of experience. He has built software products and services for companies and clients such as Cisco, Nuamedia, IBM, Nokia, Telstra, Optus, Pizzahut, AT&T, Hughes, Altran, and others. Juned has a vast experience in building software products and architecting platforms of different sizes from scratch. He loves to help and mentor others and is a top 1% contributor on StackOverflow. He is passionate about cognitive CX, cloud computing, artificial intelligence, and NoSQL databases.
Read more about Juned Ahsan

Michael Harrison
Michael Harrison
author image
Michael Harrison

Michael Harrison started his career at the Australian telecommunications leader Telstra. He worked across their networks, big data, and automation teams. He is now a lead software developer and the founding member of Southbank Software, a Melbourne based startup that builds tools for the next generation of database technologies.
Read more about Michael Harrison

Liviu Nedov
Liviu Nedov
author image
Liviu Nedov

Liviu Nedov is a senior consultant with more than 20 years of experience in database technologies. He has provided professional and consulting services to customers in Australia and Europe. Throughout his career, he has designed and implemented large enterprise projects for customers like Wotif Group, Xstrata Copper/Glencore, and the University of Newcastle and Energy, Queensland. He is currently working at Data Intensity, which is the largest multi-cloud service provider for applications, databases, and business intelligence. In recent years, he is actively involved in MongoDB NoSQL database projects, database migrations, and cloud DBaaS (Database as a Service) projects.
Read more about Liviu Nedov

View More author details
Right arrow

13. MongoDB Case Study

Overview

In this chapter, you will learn how MongoDB can be used in a business use case. It begins with a scenario wherein an imaginary city council and a local start-up jointly develop a mobile-application-based bike-sharing platform. It will then cover a detailed project proposal and a few challenges, and how the challenges are solved by using a MongoDB Atlas-based Database-as-a-Service solution. Finally, you will explore how MongoDB can be used for some use cases, go through each of them, and verify that the database design covers all the requirements.

Introduction

So far in this book, we have successfully mastered various aspects of MongoDB, from a basic introduction to disaster recovery. For any tool or technology that you choose to learn, it is important to learn how it is used, and that is what we have achieved in the previous chapters. This final chapter, then, will focus on using this technology to solve real-life problems and to make life easier.

In this chapter, we will study a use case of an imaginary city council and their upcoming bike-sharing project. First, we will look at the details of the project and see why it is needed; then, we will cover the requirements and find out how MongoDB can solve their problem.

Fair Bay City Council

Fair Bay is a city located on the east coast of North Roseland and is traditionally known for its pleasant climate and historical significance. It is also one of the major business hubs of the country. Over the last two decades, this city has generated tremendous job opportunities and attracted talent from all over the country and across the globe. Consequently, it has seen a huge population rise over the last decade, which in turn has boosted the city's real estate market.

The city is expanding at a fast pace, and the local city council is working hard to assess and redevelop the city's basic infrastructure and facilities to maintain its ease of living index. They frequently conduct surveys and assessments of their public infrastructures to identify some of the most common issues raised by the public.

In past assessments and surveys, the following concerns were repeatedly raised by the residents of the local communities:

  • Local transport...

Fair Bay City Bikes

Densely populated metropolitan cities often suffer from traffic congestion and overcrowded public transport. A bike-sharing program is a sustainable way of traveling for several reasons. It provides a healthier and cheaper mode of transportation than using cars, public transport, or private bikes. It involves procuring and parking bikes in various locations across the city. These bikes can be used by the public, on a first come first serve basis, to travel into the city. Typically, the booking and tracking of the bikes are controlled via an online platform. Studies and surveys have concluded that a well-implemented bike-sharing program can:

  • Reduce traffic congestion
  • Improve air quality
  • Reduce car and public transport usage
  • Help people save money spent on other vehicles
  • Encourage healthier lifestyles
  • Improve the sense of community

For these reasons, many cities are actively encouraging bike riding by providing bike-sharing platforms...

Technical Discussions and Decisions

The proposal is highly appreciated by the council members, and they are impressed with its cutting-edge features and low-cost implementations, as the dockless system is a lot cheaper than using docking bikes. The council is ready to procure the bikes, construct cycle lanes, and implement the signaling system throughout the city. They will also prepare the usage and safety guidelines as well as handling advertising. The team at the start-up is responsible for building the IT infrastructure and mobile application.

The council has insisted that the team keep the IT infrastructure cost to a minimum, reduce the overall rollout time, and build a scalable and flexible system for future requirement changes. The technical team at the start-up did some research to address these conditions, as detailed in the following sections.

Quick Rollout

The team is on a tight schedule and needs to find a way to build fast and ship fast. The key to achieve...

Database Design

As per the requirements described in the previous sections, the three basic entities to be persisted are user, vehicle, and ride. The user and vehicle entities will store the attributes of users and vehicles respectively, while the ride entity will be created whenever a new ride is commenced.

Apart from the basic entities, an additional entity is needed to track the bike ride logs. For each active ride, the system captures and logs the bike's location. The logs will be used for reporting and analytics purposes.

Because of the document-based dataset offered by MongoDB, all the entities can easily be designed as collections. These collections and some of their sample records will be explored in the next sections.

Users

The users collection holds data for all who have registered in the system. The following code snippet shows a sample document that represents one of the registered users:

{
    "_id" : "a6e36e30-41fa...

Use Cases

The preceding sections provided an overview of the City Bikes system, the requirements and considerations, and the database structure. Now, we will list the system use cases using some example scenarios and the database queries to run through them. This will help verify the correctness of the design and help ensure that no requirement is missed.

User Finds Available Bikes

Consider a situation in which a user opens the app on their mobile phone and clicks to find a bike in a radius of 300 meters from their location. The user's current coordinates are Longitude 111.189528 and Latitude -72.454567. The next snippet shows the corresponding database query:

db.vehicles.find({
    "vehicle_type" : "bike", 
    "status" : "available",
    "location" : {
        $near : {
        ...

Summary

This chapter explored the City Bikes project implemented by an imaginary city council. This began with a consideration of the predicted problems faced by the council and how the project proposal might address those problems. Among these considerations were the council's time and budget, uncertain requirements, and the technical team's decision to use a MongoDB Atlas-based Database-as-a-Service (DBaaS) solution to address all these issues. You studied the database design in detail and reviewed MongoDB queries to log, implement, and resolve several example scenarios in this example system.

Throughout this course, you have been introduced to various features and benefits of MongoDB through practical examples and applications. You started with the basics of MongoDB, looking at its nature and function, and how it differs from traditional RDBMS databases. You then uncovered the benefits offered by its JSON-based data structure and flexible schema. Next, you learned the...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
MongoDB Fundamentals
Published in: Dec 2020Publisher: PacktISBN-13: 9781839210648
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (4)

author image
Amit Phaltankar

Amit Phaltankar is a software developer and a blogger experienced in building lightweight and efficient software components. He specializes in wiring web-based applications and handling large-scale data sets using traditional SQL, NoSQL, and big data technologies. He is experienced in many technology stacks and loves learning and adapting to newer technology trends. Amit is passionate about improving his skill set and loves guiding and grooming his peers and contributing to blogs. He is also an author of MongoDB Fundamentals.
Read more about Amit Phaltankar

author image
Juned Ahsan

Juned Ahsan is a software professional with more than 14 years of experience. He has built software products and services for companies and clients such as Cisco, Nuamedia, IBM, Nokia, Telstra, Optus, Pizzahut, AT&T, Hughes, Altran, and others. Juned has a vast experience in building software products and architecting platforms of different sizes from scratch. He loves to help and mentor others and is a top 1% contributor on StackOverflow. He is passionate about cognitive CX, cloud computing, artificial intelligence, and NoSQL databases.
Read more about Juned Ahsan

author image
Michael Harrison

Michael Harrison started his career at the Australian telecommunications leader Telstra. He worked across their networks, big data, and automation teams. He is now a lead software developer and the founding member of Southbank Software, a Melbourne based startup that builds tools for the next generation of database technologies.
Read more about Michael Harrison

author image
Liviu Nedov

Liviu Nedov is a senior consultant with more than 20 years of experience in database technologies. He has provided professional and consulting services to customers in Australia and Europe. Throughout his career, he has designed and implemented large enterprise projects for customers like Wotif Group, Xstrata Copper/Glencore, and the University of Newcastle and Energy, Queensland. He is currently working at Data Intensity, which is the largest multi-cloud service provider for applications, databases, and business intelligence. In recent years, he is actively involved in MongoDB NoSQL database projects, database migrations, and cloud DBaaS (Database as a Service) projects.
Read more about Liviu Nedov