FastAPI+React全栈开发03 为什么使用MongoDB

news/2024/7/15 17:01:54 标签: fastapi, react.js, mongodb

Chapter01 Web Development and the FARM Stack

03 Why use MongoDB

FastAPI+React全栈开发03 为什么使用MongoDB

In the following paragraphs, we will go through the main features of our selected database system - MongoDB - and give a high-level overview of the features that make it an excellent fit for our FARM stack. After a brief introduction of some specificities of the database, in the following chapter, we will go over the setup and create a working database environment that will enable us to showcase some basic methods.

在下面的段落中,我们将介绍所选数据库系统MongoDB的主要特性,并对使其非常适合FARM堆栈的特性进行高级概述。在简要介绍了数据库的一些特性之后,在下一章中,我们将检查设置并创建一个工作的数据库环境,使我们能够展示一些基本方法。

MongoDB is the database of choice in the FARM stack. It is fast, scalable, and document-oriented database that enables flexible schemas and, thus interative and rapid development. MongoDB is able to accommodate data structures of varing complexities, and its querying and aggregation methods make it an excellent choice for a flexible REST API framework such as FastAPI, coupled with an official Python driver. It has a high level of adoption and maturity and is one of the pillars of the NoSQL data storage movement that took the web development world by storm a decade ago.

MongoDB是FARM堆栈中首选的数据库。它是一种快速的、可伸缩的、面向文档的数据库,支持灵活的模式和交互式的、快速的开发。MongoDB能够适应各种复杂的数据结构,它的查询和聚合方法使它成为灵活的REST API框架(如FastAPI)的绝佳选择,再加上官方的Python驱动程序。它具有很高的采用率和成熟度,是十年前席卷web开发世界的NoSQL数据存储运动的支柱之一。

The main features that make MongoDB an ideal candidate for a flexible and fast-paced development environment, prototyping, and iterative development are listed as follows:

  • Easy and cheap: It is easy and fast to set up using an online cloud service that offers a generous free tier, while local installation is always on option.
  • Flexibility: The NoSQL nature of the database enables extremely flexible models and fast iterations and modifications on the fly.
  • Web-friendly format: The native data format BSON is practically a binary version of JSON, which, in turn, is the de facto data format of the modern web, so no complex parsing or transformations are necessary.
  • Complex nested structures: MongoDB documents allow other documents and arrays of documents to be embedded, which naturally translates into the data flow of a modern data web app (for example, we can embed all of the comments into the blog post they refer to). Denormalization is encouraged.
  • Simple intuitive syntax: The methods for performing basic CRUD operations (that is create, read, update, and delete), coupled with powerful aggregation frameworks and projections, allow us to achieve mostly all data reads relatively simply through the use of drivers, and the commands should be intuitive for anyone with a bit of SQL experience.
  • Built with scalability in mind: MongoDB is built from the ground up with several objectives - scalability, speed, and the ability to handle huge (huMONGOus) amounts of data.
  • Community and documentation: Lastly, MongoDB is backed by a mature company and strong community, and it offers various tools to facilitate the development and prototyping process. For instance, Compass is a desktop application that enables users to manage and admister databases. The framework of the serverless functions is constantly being updated and upgraded, and there are excellent drivers for virtually every programming language.

使MongoDB成为灵活、快节奏开发环境、原型和迭代开发的理想候选者的主要特性如下:

  • 简单和便宜:使用在线云服务进行设置既简单又快速,该服务提供了一个慷慨的免费层,而本地安装始终是一个选项。
  • 灵活性:数据库的NoSQL特性使得模型非常灵活,并且可以快速迭代和修改。
  • web友好格式:本机数据格式BSON实际上是JSON的二进制版本,而JSON反过来又是现代web的事实上的数据格式,因此不需要复杂的解析或转换。
  • 复杂的嵌套结构:MongoDB文档允许嵌入其他文档和文档数组,这自然会转化为现代数据web应用程序的数据流(例如,我们可以将所有评论嵌入到他们引用的博客文章中)。鼓励非正规化。
  • 简单直观的语法:执行基本CRUD操作(即创建、读取、更新和删除)的方法,加上强大的聚合框架和投影,允许我们通过使用驱动程序相对简单地实现大多数所有数据读取,并且对于任何具有一点SQL经验的人来说,这些命令都应该是直观的。
  • 构建时考虑到可扩展性:MongoDB是从头开始构建的,有几个目标-可扩展性,速度和处理大量数据的能力。
  • 社区和文档:最后,MongoDB由一个成熟的公司和强大的社区支持,它提供了各种工具来促进开发和原型过程。例如,Compass是一个桌面应用程序,它使用户能够管理和管理数据库。无服务器功能的框架不断更新和升级,并且几乎每种编程语言都有优秀的驱动程序。

I believe that in some cases, and this includes a lot of cases, MongoDB should be your first choice, especially when you are designing something that still has a very fluid or vague specification, and let’s be honest, that happens a lot more than we would like to admit.

我相信在某些情况下,这包括很多情况下,MongoDB应该是你的第一选择,特别是当你设计的东西仍然有一个非常流动或模糊的规范,让我们说实话,这种情况比我们想承认的要多得多。

Of course, MongoDB is not a silver bullet, and some drawbacks are worth noticing upfront. On the one hand, the schemaless design and the ability to insert any type of data into your database might be a bit panic, inducing but translates to the need for stronger data integrity validation on the backend side. We will see how Pydantic, an excellent Python validation and type-enforcement library, can help us with that. The absence of complex joins, which are present in the SQL world, might be a dealbreaker for some types of applications. For analytics-intensive applications that require numerous complex queries, relational databases are a better, and often the only possible, solution. Finally, for mission critical applications that require adherence to the ACID principles (that is, atomicity, consistency, isolation, and durability) of transactions, MongoDB or any NoSQL database system migh not be the right solution.

当然,MongoDB不是灵丹妙药,一些缺点值得提前注意。一方面,无模式设计和将任何类型的数据插入数据库的能力可能会让人有点恐慌,这会导致后端需要更强的数据完整性验证。我们将看到Pydantic(一个优秀的Python验证和类型强制库)如何帮助我们实现这一点。缺少SQL世界中存在的复杂连接,可能会破坏某些类型的应用程序。对于需要大量复杂查询的分析密集型应用程序,关系数据库是更好的解决方案,而且通常是唯一可能的解决方案。最后,对于需要遵守事务的ACID原则(即原子性、一致性、隔离性和持久性)的关键任务应用程序,MongoDB或任何NoSQL数据库系统可能不是正确的解决方案。

Now that we understand what MongoDB brings to the table in terms of scalability, but especially flexibility with its schema less approach, let us take a look at the REST API framework of choice, FastAPI, and learn how it can help us leverage that schema-less approach and simplify our interactions with the data.

现在我们已经了解了MongoDB在可伸缩性方面带来了什么,尤其是它的无模式方法的灵活性,让我们来看看选择的REST API框架FastAPI,并了解它如何帮助我们利用无模式方法并简化我们与数据的交互。


http://www.niftyadmin.cn/n/5450454.html

相关文章

大型网站集群管理负载均衡

课程介绍 结合企业大规模应用,解决应用高并发问题,解决单节点故障问题,缓存数据库的应用。学完掌握知识点:企业应用实现四七层负载均衡,以及Nginx等应用的高可用性,Redis缓存数据库的部署应用以及高可用方…

SpringBoot集成Solr全文检索

SrpingBoot 集成 Solr 实现全文检索 一、核心路线 使用 Docker 镜像部署 Solr 8.11.3 版本服务使用 ik 分词器用于处理中文分词使用 spring-boot-starter-data-solr 实现增删改查配置用户名密码认证使用 poi 和 pdfbox 组件进行文本内容读取文章最上方有源码和 ik 分词器资源…

rust标准库std::env环境相关的常量

在env这个库中,有一些环境相关的常量,这些常量在std::env::consts这个模块下面,通过这个依赖库可以获取到当前程序所运行的环境和运行的目录地址等信息。 env 常量 std::env下面一些系统相关的常量: ARCH DLL_EXTENSION DLL_P…

[NKCTF 2024]web解析

文章目录 my first cms全世界最简单的CTF解法一解法二 my first cms 打开题目在最下面发现是CMS Made Simple,版本为2.2.19 扫一下发现存在后台登陆界面,直接访问 用字典爆破下admin的密码为Admin123 然后直接登录,去漏洞库搜一下其实存在…

GuLi商城-商品服务-API-三级分类-查询-树形展示三级分类数据

1、网关服务配置路由 2、商品服务 3、启动本地nacos&#xff0c;打开nacos地址看nacos服务列表 4、编写VUE <template> <el-tree :data"menus" :props"defaultProps" node-click"handleNodeClick"></el-tree> </template…

Pandas库常用方法、函数集合

Pandas是Python数据分析处理的核心第三方库&#xff0c;它使用二维数组形式&#xff0c;类似Excel表格&#xff0c;并封装了很多实用的函数方法&#xff0c;让你可以轻松地对数据集进行各种操作。 这里列举下Pandas中常用的函数和方法&#xff0c;方便大家查询使用。 读取 写…

通过Caliper进行压力测试程序,且汇总压力测试问题解决

环境要求 第一步. 配置基本环境 部署Caliper的计算机需要有外网权限&#xff1b;操作系统版本需要满足以下要求&#xff1a;Ubuntu > 16.04、CentOS > 7或MacOS > 10.14&#xff1b;部署Caliper的计算机需要安装有以下软件&#xff1a;python 2.7、make、g&#xff…

java Web餐馆订单管理系统用eclipse定制开发mysql数据库BS模式java编程jdbc

一、源码特点 JSP 餐馆订单管理系统是一套完善的web设计系统&#xff0c;对理解JSP java 编程开发语言有帮助&#xff0c;系统具有完整的源代码和数据库&#xff0c;系统主要采用B/S模式开发。开发环境为TOMCAT7.0,eclipse开发&#xff0c;数据库为Mysql5.0&#xff0c;使…