Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Full Stack FastAPI, React, and MongoDB
Full Stack FastAPI, React, and MongoDB

Full Stack FastAPI, React, and MongoDB: Fast-paced web app development with the FARM stack , Second Edition

Arrow left icon
Profile Icon MongoDB Inc. Profile Icon Marko Aleksendrić Profile Icon Shrey Batra Profile Icon Shubham Ranjan Profile Icon Rachelle Palmer +1 more Show less
Arrow right icon
€44.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Aug 2024 312 pages 2nd Edition
eBook
€44.99
Paperback
€56.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon MongoDB Inc. Profile Icon Marko Aleksendrić Profile Icon Shrey Batra Profile Icon Shubham Ranjan Profile Icon Rachelle Palmer +1 more Show less
Arrow right icon
€44.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Aug 2024 312 pages 2nd Edition
eBook
€44.99
Paperback
€56.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€44.99
Paperback
€56.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
Table of content icon View table of contents Preview book icon Preview Book

Full Stack FastAPI, React, and MongoDB

Setting Up the Database with MongoDB

In this chapter, you will explore some of the main features of MongoDB through several simple yet illustrative examples. You will learn about the basic commands of the MongoDB Query API to start interacting with your data stored in a MongoDB database. You will learn the essential commands and methods that will enable you to insert, manage, query, and update your data.

The aim of this chapter is to help you understand how easy it is to set up a MongoDB database on your local machine or in the cloud and perform the operations that might be needed in a fast-paced web development process.

Querying, through MongoDB methods and aggregation, is best learned by experimenting with data. This chapter utilizes real-world sample datasets provided by MongoDB Atlas that are loaded into your cloud database. You will learn to execute CRUD and aggregation queries against them.

This chapter will cover the following topics:

  • The structure of a MongoDB...

Technical requirements

For this chapter, you will require MongoDB version 7.0.7 and Windows 11 (and Ubuntu 22.04 LTS).

MongoDB version 7.0 is compatible with the following:

  • Windows 11, Windows Server 2019, or Windows Server 2022 (64-bit versions)
  • Ubuntu 20.04 LTS (Focal) and Ubuntu 22.04 LTS (Jammy) for Linux (64-bit releases)

The following are recommended system configurations:

  • A desktop or laptop with at least 8 GB of RAM.
  • There are no CPU requirements specified as such but make sure it’s modern (a multi-core processor) to ensure efficient performance.

The structure of a MongoDB database

MongoDB is widely regarded as the leading NoSQL database in terms of popularity and usage—its power, ease of use, and versatility make it an excellent choice for large- and small-scale projects. Its scalability and performance enable the data layer of your app to have a very solid foundation.

In the following sections, you will take a deeper look into the basic concepts and building blocks of MongoDB: the document, the collection, and the database. Since this book takes a bottom-up approach, you will start from the very bottom and see an overview of the simplest data structures available in MongoDB and then take it up from there into documents, collections, and so on.

Documents

MongoDB is a document-oriented database. But what does that actually mean?

In MongoDB, documents serve a similar purpose to rows in a traditional relational database. Each document in MongoDB is a data structure that consists of key-value pairs, representing...

Installing MongoDB and related tools

MongoDB is not just a database service provider, but a full-fledged developer data platform that has a set of technologies built around the core database to meet all your data needs and improve your productivity as a developer. Let’s examine the following components that you will be installing or using in the following sections:

  • MongoDB Community Edition: A free version of MongoDB that runs on all major operating systems. It is what you are going to use to play around with data locally.
  • MongoDB Compass: A graphical user interface (GUI) for managing, querying, aggregating, and analyzing MongoDB data in a visual environment. Compass is a mature and useful tool that you’ll be using throughout your initial querying and aggregation explorations.
  • MongoDB Atlas: The database-as-a-service solution from MongoDB. This offering is one of the main reasons MongoDB is a central part of the FARM stack. It is relatively easy to set...

Installing MongoDB and Compass on Windows

In this section, you will learn how to install the latest version of MongoDB Community Edition, which at the time of writing is 7.0. MongoDB Community is only supported on 64-bit versions of Windows on x86_64 architecture. Windows versions supported are Windows 11, Windows Server 2019, and Windows Server 2022. To install MongoDB and Compass, you can refer to the following steps.

Note

We strongly advise you to check the instructions on the MongoDB website (https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-windows/) to ensure you have access to the latest information, as they might slightly change.

  1. To download the installer, head over to the MongoDB Download Center at https://www.mongodb.com/try/download/community, select the Windows version, and click on Download as follows:

Figure 2.1: MongoDB download page

  1. Next, execute it. If a security prompt displays Open Executable File...

Installing the MongoDB Shell (mongosh)

After installing MongoDB Community Server and Compass on your computer, you will next install mongosh, the MongoDB Shell.

Note

For instructions on other operating systems, please visit the MongoDB documentation: https://www.mongodb.com/docs/mongodb-shell/install/.

Here’s how you can do it for Windows:

  1. Navigate to the MongoDB Download Center (https://www.mongodb.com/try/download/shell) and, in the Tools section, select MongoDB Shell.
  2. From the dropdowns, select the Windows version and the msi package and click on Download.

Figure 2.4: Download the MongoDB Shell

  1. Next, locate the msi package on your computer and execute it. If a security prompt asks Open Executable File, select Yes and proceed to the MongoDB setup wizard. The wizard will open the following page. Click on Next:

Figure 2.5: The MongoDB Shell Setup Wizard

  1. In the prompt, select the...

MongoDB Database Tools

The MongoDB Database Tools are a collection of command-line utilities for working with a MongoDB deployment. Some of the common database tools are as follows:

  • mongoimport: Imports content from an extended JSON, CSV, or TSV export file
  • mongoexport: Produces a JSON or CSV export of data stored in a mongod instance
  • mongodump: Creates a binary export of the contents of a mongod database

There are some other tools, such as mongorestore, bsondump, mongostat, mongotop, and mongofiles. The MongoDB Database Tools can be installed with an MSI installer (or downloaded as a ZIP archive).

Note

The msi package can be downloaded from the MongoDB Download Center (https://www.mongodb.com/try/download/database-tools).

After downloading, you can follow the installation instructions provided in the MongoDB documentation (https://www.mongodb.com/docs/database-tools/installation/installation-windows/).

The next section provides a walk-through of...

Installing MongoDB and Compass on Linux: Ubuntu

Linux offers numerous benefits for the development and management of local servers, but most importantly, should you decide that the database-as-a-service of MongoDB isn’t what you want to use anymore, you will probably want to work on a Linux-based server.

In this book, we will go over the installation process on Ubuntu version 22.04 LTS (Jammy), while the MongoDB version also supports Ubuntu 20.04 LTS (Focal) on x86_64 architecture. The necessary steps to install MongoDB Ubuntu will be listed here, but you should always check the MongoDB Ubuntu installation page (https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/) for recent changes. The process, however, shouldn’t change.

The following actions are to be performed in a Bash shell. Download the public key that will allow you to install MongoDB, then you will create a list file and reload the package manager. Similar steps are required for other...

Setting up Atlas

MongoDB Atlas—a cloud database service provided by MongoDB—is one of the strongest selling points of MongoDB.

MongoDB Atlas is a fully managed database service, which means that MongoDB handles the infrastructure management, database setup, configuration, and maintenance tasks for you. This allows you to focus on developing your applications instead of managing the underlying infrastructure.

Note

The processes of signing up and setting up a MongoDB Atlas instance are well documented at https://www.mongodb.com/docs/atlas/getting-started/.

There are two ways in which you can set up your Atlas account:

  • Atlas UI (website)
  • Atlas CLI (command line)

The Atlas CLI provides a dedicated CLI for MongoDB Atlas, allowing you to manage your Atlas database deployments and Atlas Search directly from your terminal. In this book, you will see how to do it from the UI.

Head over to https://www.mongodb.com/cloud/atlas/register to create...

MongoDB querying and CRUD operations

Let’s see MongoDB in action and experience firsthand the power of the most popular NoSQL database. This section will show you the most essential MongoDB commands, through simple examples. These methods will enable you, as a developer, to take control of your data, create new documents, query documents by using different criteria and conditions, perform simple and more complex aggregations, and output data in various forms.

Although you will be talking to MongoDB through the Python drivers (Motor and PyMongo), it is helpful to learn how to write queries directly at first. You’ll begin by querying the sample_mflix.movies dataset that was imported into your cluster at the time of cluster creation, then you’ll go through the process of creating new data—inserting, updating, and so on.

Let’s first define the two options for executing MongoDB commands, as follows:

  • Compass GUI
  • MongoDB Shell (mongosh...

Querying in MongoDB

This section will show the use of the sample_mflix.movies collection as an example for demonstration. Working with real data with some expected query results helps reinforce the acquired notions and makes understanding the underlying processes easier and more thorough.

The most frequent MongoDB query language commands—and the ones that this chapter will be covering—are as follows:

  • find(): Finds and selects documents matching simple or complex criteria
  • insertOne(): Inserts a new document into the collection
  • insertMany(): Inserts an array of documents into the collection
  • updateOne() and updateMany(): Update one or more documents according to some criteria
  • deleteOne() and deleteMany(): Delete one or more documents from the collection

There are 21,349 documents in the sample_mflix.movies collection. To query for all the documents, type the following command in the MongoDB Shell:

db.movies.find()

The preceding command...

Summary

This chapter detailed the basic building blocks that define MongoDB and its structure. You have seen how to set up a database in the cloud using MongoDB Atlas and explored the basics of creating, updating, and deleting documents. Further, this chapter detailed the aggregation pipeline framework—a strong analytic tool.

The next chapter will show how to create APIs with FastAPI—an exciting and new Python framework. We will provide a minimal yet complete guide of the main concepts and features, which should hopefully convince you that building APIs can be fast, efficient, and fun.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn the basics of MongoDB to be able to model any type of data
  • Explore the powerful Python web development ecosystem with Pydantic and FastAPI
  • Future-proof your applications by integrating ChatGPT or other LLMs
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

Discover how to harness the power of the FARM stack—FastAPI, React, and MongoDB—to develop production-ready web applications of varying complexity. Written by a team of industry experts, including MongoDB champions and product leaders, this fast-paced, hands-on guide equips beginners with essential skills to build web applications efficiently. Introducing each element of the stack, the book demonstrates how to seamlessly integrate them to create a medium-sized web application. You'll set up MongoDB as a document store, construct a simple API with FastAPI, and build an application using React. The guide also covers enhancing application security through authentication and authorization with JSON Web Tokens. Beyond mastering the stack, you'll get to grips with integrating Large Language Models (like ChatGPT) for advanced functionality, such as automated email sending. Additionally, you'll learn how to make the most of Next.js 14, a robust full-stack framework offering improved developer experience. By the end of the book, you'll have created functional applications and gained the foundation to explore diverse and more specialized domains, expanding your development horizons.

Who is this book for?

The book is for intermediate web developers with basic JavaScript and Python knowledge who want to enhance their developer skills, master a powerful and flexible stack, and write better applications faster.

What you will learn

  • Set up and manage MongoDB databases and collections, and model data
  • Leverage the power of FastAPI to write complex APIs using pure Python
  • Create frontends of varying complexity with the React library
  • Build and deploy robust and secure backends using FastAPI and MongoDB
  • Ship production-ready applications with Next.js 14, applying your React and backend knowledge
  • Integrate Large Language Models, send emails, and do much more with the flexible FARM stack

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Aug 23, 2024
Length: 312 pages
Edition : 2nd
Language : English
ISBN-13 : 9781835886779
Vendor :
MongoDB
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning

Product Details

Publication date : Aug 23, 2024
Length: 312 pages
Edition : 2nd
Language : English
ISBN-13 : 9781835886779
Vendor :
MongoDB
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 136.97 147.97 11.00 saved
Building AI Intensive Python Applications
€56.99
Python Feature Engineering Cookbook
€22.99 €33.99
Full Stack FastAPI, React, and MongoDB
€56.99
Total 136.97 147.97 11.00 saved Stars icon

Table of Contents

13 Chapters
Chapter 1: Web Development and the FARM Stack Chevron down icon Chevron up icon
Chapter 2: Setting Up the Database with MongoDB Chevron down icon Chevron up icon
Chapter 3: Python Type Hints and Pydantic Chevron down icon Chevron up icon
Chapter 4: Getting Started with FastAPI Chevron down icon Chevron up icon
Chapter 5: Setting Up a React Workflow Chevron down icon Chevron up icon
Chapter 6: Authentication and Authorization Chevron down icon Chevron up icon
Chapter 7: Building a Backend with FastAPI Chevron down icon Chevron up icon
Chapter 8: Building the Frontend of the Application Chevron down icon Chevron up icon
Chapter 9: Third-Party Services Integration with FastAPI and Beanie Chevron down icon Chevron up icon
Chapter 10: Web Development with Next.js 14 Chevron down icon Chevron up icon
Chapter 11: Useful Resources and Project Ideas Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Emiru Aug 31, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
i have just started this book stumbled on it during a React Js class and was hesitant at first. I was blown away by the first few paragraphs and how the writter takes the time to explain why each of the technologies. I have just installed MongoDB and i can see this book being my companion for many years to come. Thank you.
Subscriber review Packt
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.