Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
MongoDB Fundamentals

You're reading from  MongoDB Fundamentals

Product type Book
Published in Dec 2020
Publisher Packt
ISBN-13 9781839210648
Pages 748 pages
Edition 1st Edition
Languages
Concepts
Authors (4):
Amit Phaltankar Amit Phaltankar
Profile icon Amit Phaltankar
Juned Ahsan Juned Ahsan
Profile icon Juned Ahsan
Michael Harrison Michael Harrison
Profile icon Michael Harrison
Liviu Nedov Liviu Nedov
Profile icon Liviu Nedov
View More author details

Table of Contents (15) Chapters

Preface
1. Introduction to MongoDB 2. Documents and Data Types 3. Servers and Clients 4. Querying Documents 5. Inserting, Updating, and Deleting Documents 6. Updating with Aggregation Pipelines and Arrays 7. Data Aggregation 8. Coding JavaScript in MongoDB 9. Performance 10. Replication 11. Backup and Restore in MongoDB 12. Data Visualization 13. MongoDB Case Study Appendix

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 2020 Publisher: Packt ISBN-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.
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 €14.99/month. Cancel anytime}