博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MongoDB和Python简介
阅读量:2522 次
发布时间:2019-05-11

本文共 22110 字,大约阅读时间需要 73 分钟。

Python is a powerful programming language used for many different types of applications within the development community. Many know it as a flexible language that can handle just about any task. So, what if our complex Python application needs a database that’s just as flexible as the language itself? This is where NoSQL, and specifically , come in to play.

Python是一种功能强大的编程语言,可用于开发社区中的许多不同类型的应用程序。 许多人都知道它是一种可以处理几乎所有任务的灵活语言。 那么,如果我们复杂的Python应用程序需要一个与语言本身一样灵活的数据库呢? 这就是NoSQL(特别是发挥作用的地方。

Python and MongoDB

Throughout this article we’ll show you how to use Python to interface with the popular (v) database, along with an overview of SQL vs. NoSQL, (v), and (v), among other things.

在整篇文章中,我们将向您展示如何使用Python与流行的 (v )数据库进行接口,以及SQL vs. NoSQL, (v )和 (v )的概述 ),等等。

SQL与NoSQL (SQL vs NoSQL)

In case you aren’t familiar with it, MongoDB is a database which has become pretty popular throughout the industry in recent years. NoSQL databases provide features of retrieval and storage of data in a much different way than their relational database counterparts.

如果您不熟悉它,MongoDB是一个数据库,近年来在整个行业中非常流行。 NoSQL数据库提供的数据检索和存储功能与其关系数据库中的数据库有很大不同。

For decades, SQL databases used to be one of the only choices for developers looking to build large, scalable systems. However, the ever-increasing need for the ability to store complex data structures led to the birth of NoSQL databases, which allow a developer to store heterogeneous and structure-less data.

几十年来,SQL数据库一直是希望构建大型可伸缩系统的开发人员的唯一选择之一。 但是,对存储复杂数据结构能力的不断增长的需求催生了NoSQL数据库的诞生,这使开发人员可以存储异构且无结构的数据。

When it comes to the choices available, most people have to ask themselves the ultimate question, “SQL or NoSQL?” Both SQL and NoSQL have their strengths and weaknesses, and you should choose the one that fits your application requirements the best. Here are a few differences between the two:

当谈到可用的选择时,大多数人不得不问自己一个最终的问题,“ SQL还是NoSQL?” SQL和NoSQL都有其优点和缺点,因此您应该选择最适合您的应用程序需求SQL和NoSQL。 两者之间有一些区别:

SQL

SQL

  • The model is of a relational nature
  • Data is stored in tables
  • Suitable for solutions where every record is of the same kind and possesses the same properties
  • Adding a new property means you have to alter the whole schema
  • The schema is very strict
  • transactions are supported
  • Scales well vertically
  • 该模型具有关系性
  • 数据存储在表中
  • 适用于每个记录属于相同种类且具有相同属性的解决方案
  • 添加新属性意味着您必须更改整个架构
  • 模式非常严格
  • 支持交易
  • 垂直缩放良好

NoSQL

NoSQL

  • The model is non-relational
  • May be stored as JSON, key-value, etc. (depending on type of NoSQL database)
  • Not every record has to be of the same nature, making it very flexible
  • Add new properties to data without disturbing anything
  • No schema requirements to adhere to
  • Support for ACID transactions can vary depending on which NoSQL DB is used
  • Consistency can vary
  • Scales well horizontally
  • 该模型是非关系的
  • 可以存储为JSON,键值等(取决于NoSQL数据库的类型)
  • 并非每个记录都必须具有相同的性质,因此使其非常灵活
  • 在不干扰任何内容的情况下向数据添加新属性
  • 无需遵守任何架构要求
  • 对ACID事务的支持可能会有所不同,具体取决于所使用的NoSQL DB
  • 一致性可能会有所不同
  • 水平缩放好

There are many other differences between the two types of databases but those mentioned above are some of the more important differences to know.

两种类型的数据库之间还有许多其他差异,但是上面提到的是一些需要了解的更重要的差异。

Depending on your specific scenario, the use of a SQL database may be preferred, while in other scenarios NoSQL is the more obvious choice to make. When choosing a database you should consider the strengths and weaknesses of each database carefully.

根据您的特定方案,可能首选使用SQL数据库,而在其他方案中,NoSQL是更明显的选择。 选择数据库时,应仔细考虑每个数据库的优点和缺点。

One of the great things about NoSQL is that there are many different types of databases to choose from, and each has its own use-cases:

NoSQL的一大优点是,有许多不同类型的数据库可供选择,每种都有自己的用例:

  • Key-Value Store:
  • Document Store: , ,
  • Column Store:
  • Data-Structures:
  • 键值存储:
  • 文档存储: , ,
  • 列存储:
  • 数据结构:

There are quite a few more, but these are some of the more common types.

还有很多,但是这些是一些较常见的类型。

In recent years, SQL and NoSQL databases have even begun to merge. For example, PostgreSQL now supports storing and querying JSON data, much like Mongo. With this, you can now achieve much of the same with Postgres as you can with Mongo, but you still don’t get many of the Mongo advantages (like horizontal scaling and the simple interface, etc.). As puts it:

近年来,SQL和NoSQL数据库甚至开始合并。 例如,PostgreSQL现在支持存储和查询JSON数据,就像Mongo一样。 这样,您现在可以使用Postgres达到与Mongo相同的功能,但是仍然无法获得许多Mongo的优势(例如水平缩放和简单的界面等)。 如 :

If your active data sits in the relational schema comfortably and the JSON content is a cohort to that data then you should be fine with PostgreSQL and it’s much more efficient JSONB representation and indexing capabilities. If though, your data model is that of a collection of mutable documents then you probably want to look at a database engineered primarily around JSON documents like MongoDB or RethinkDB.

如果您的活动数据舒适地位于关系模式中,并且JSON内容是该数据的同类,那么您应该对PostgreSQL没问题,它是更有效的JSONB表示和索引功能。 但是,如果您的数据模型是可变文档的集合,那么您可能想要查看主要围绕JSON文档(如MongoDB或RethinkDB)设计的数据库。

MongoDB (MongoDB)

Let’s now shift our attention to the main focus of this article and shed some light on the specifics of MongoDB.

现在,让我们将注意力转移到本文的主要焦点上,并对MongoDB的细节有所了解。

MongoDB is a document-oriented, open-source database program that is platform-independent. MongoDB, like some other NoSQL databases (but not all!), stores its data in documents using a JSON structure. This is what allows the data to be so flexible and not require a schema.

MongoDB是独立于平台的面向文档的开源数据库程序。 像其他一些NoSQL数据库(但不是全部!)一样,MongoDB使用JSON结构将其数据存储在文档中。 这就是使数据如此灵活且不需要架构的原因。

Some of the more important features are:

一些更重要的功能是:

  • You have support for many of the standard query types, like matching (==), comparison (<, >), or even regex
  • You can store virtually any kind of data – be it structured, partially structured, or even polymorphic
  • To scale up and handle more queries, just add more machines
  • It is highly flexible and agile, allowing you to quickly develop your applications
  • Being a document-based database means you can store all the information regarding your model in a single document
  • You can change the schema of your database on the fly
  • Many relational database functionalities are also available in MongoDB (e.g. indexing)
  • 您支持许多标准查询类型,例如匹配( == ),比较( <> )甚至是正则表达式
  • 您几乎可以存储任何类型的数据-结构化,部分结构化甚至是多态的
  • 要扩大规模并处理更多查询,只需添加更多计算机
  • 它具有高度的灵活性和敏捷性,可让您快速开发应用程序
  • 成为基于文档的数据库意味着您可以将有关模型的所有信息存储在一个文档中
  • 您可以随时更改数据库的架构
  • MongoDB中还提供了许多关系数据库功能(例如索引)

As for the operations side of things, there are quite a few tools and features for MongoDB that you just can’t find with any other database system:

至于操作方面,MongoDB有很多工具和功能,这些是其他任何数据库系统都找不到的:

  • Whether you need a standalone server or complete clusters of independent servers, MongoDB is as scalable as you need it to be
  • MongoDB also provides load balancing support by automatically moving data across the various shards
  • It has automatic failover support – in case your primary server goes down, a new primary will be up and running automatically
  • The MongoDB Management Service or MMS is a very nice web tool that provides you with the ability to track your machines
  • Thanks to the memory mapped files, you’ll save quite a bit of RAM, unlike relational databases
  • 无论您需要独立服务器还是完整的独立服务器集群,MongoDB都可根据需要进行扩展
  • MongoDB还通过在各个分片之间自动移动数据来提供负载平衡支持。
  • 它具有自动故障转移支持–万一您的主服务器关闭,新的主服务器将自动启动并运行
  • MongoDB管理服务或MMS是一个非常不错的Web工具,它使您能够跟踪计算机
  • 由于有了内存映射文件,与关系数据库不同,您将节省大量RAM。

If you take advantage of the indexing features, much of this data will be kept in memory for quick retrieval. And even without indexing on specific document keys, Mongo caches quite a bit of data using the method.

如果您利用索引功能,很多数据将保留在内存中以便快速检索。 即使没有在特定文档密钥上建立索引,Mongo也会使用方法来缓存大量数据。

While at first Mongo may seem like it’s the solution to many of our database problems, it isn’t without its drawbacks. One common drawback you’ll hear about Mongo is its lack of support for ACID transactions. Mongo does support ACID transactions in a , but not in all cases. At the single-document level, ACID transactions are supported (which is where most transactions take place anyway). However, transactions dealing with multiple documents are not supported due to Mongo’s distributed nature.

乍一看,Mongo似乎可以解决我们许多数据库问题,但它并非没有缺点。 您会听到有关Mongo的一个常见缺点是它缺乏对ACID交易的支持。 Mongo确实在支持ACID交易,但并非在所有情况下都支持。 在单文档级别,支持ACID事务(无论如何,这都是大多数事务发生的地方)。 但是,由于Mongo的分布式性质,不支持处理多个文档的事务。

Mongo also lacks support for native joins, which must be done manually (and therefore much more slowly). Documents are meant to be all-encompassing, which means, in general, they shouldn’t need to reference other documents. In the real world this doesn’t always work as much of the data we work with is relational by nature. Therefore many will argue that Mongo should be used as a complementary database to a SQL DB, but as you use MongoDB you’ll find that is not necessarily true.

Mongo还缺少对本机联接的支持,该联接必须手动完成(因此要慢得多)。 文档本应是无所不包的,这通常意味着它们不需要引用其他文档。 在现实世界中,这并不总是有效,因为我们处理的数据本质上是关系型的。 因此,许多人认为Mongo应该用作SQL DB的补充数据库,但是当您使用MongoDB时,您会发现事实不一定如此。

PyMongo (PyMongo)

Now that we’ve described what MongoDB is exactly, let’s find out how you’d actually use it with Python. The official driver published by the Mongo developers is called . This is a good place to start when first firing Python up with MongoDB. We’ll be going through some examples here, but you should also check out the since we won’t be able to cover everything.

现在,我们已经描述了MongoDB的确切含义,让我们了解如何在Python中实际使用它。 Mongo开发人员发布的官方驱动程序称为 。 这是从MongoDB首次启动Python时开始的好地方。 我们将在此处介绍一些示例,但您也应该查看因为我们无法涵盖所有​​内容。

The first thing you’ll want to do is to install PyMongo in your . The easiest way to do this is with pip:

您要做的第一件事是在您的安装PyMongo。 最简单的方法是使用pip

11

NOTE: For a more comprehensive guide check out the page of the docs and follow the steps there to get set up.

注意:有关更全面的指南,请查看文档的“ 页面,然后按照那里的步骤进行设置。

Once you are done with the setup, start your Python console and run the following command:

完成设置后,启动Python控制台并运行以下命令:

11

If it runs without raising any exception within the Python shell then your install worked just fine. If not, then carefully perform the steps again. Exit the shell once done.

如果它运行时未在Python Shell中引发任何异常,则您的安装工作正常。 如果不是,则再次仔细执行步骤。 完成后退出外壳。

Next, you have to install the actual MongoDB database.

接下来,您必须安装实际的MongoDB数据库。

If you’re on a Mac, we recommend using , but you may have a different preference. If using Homebrew, run this command:

如果您使用的是Mac,我们建议您使用 ,但您可能会有不同的偏好。 如果使用自制软件,请运行以下命令:

11

Once done, follow the directions to set up the data directory for storing data locally.

完成后,请按照说明设置数据目录以在本地存储数据。

If you’re not using a Mac, you can find some great guides on installation from the page of the official docs. There you’ll find tutorials on installing MongoDB for Linux, OS X, and Windows.

如果您使用的不是Mac,则可以从官方文档的“ 页面上找到一些很好的指南。 在那里,您将找到有关安装适用于Linux,OS X和Windows的MongoDB的教程。

Once installed, within a new terminal window, use the following command to start the Mongo daemon:

安装后,在新的终端窗口中,使用以下命令启动Mongo守护程序:

11

NOTE: Depending on your install method, you may need to run mongod with sudo.

注意:根据您的安装方法,您可能需要使用sudo运行mongod

Now let’s get started with the basics of PyMongo.

现在让我们开始学习PyMongo的基础知识。

建立连接 (Establishing a Connection)

To establish a connection we’ll use the MongoClient object.

为了建立连接,我们将使用MongoClient对象。

The first thing that we need to do in order to establish a connection is import the MongoClient class. We’ll use this to communicate with the running database instance. Use the following code to do so:

为了建立连接,我们需要做的第一件事是导入MongoClient类。 我们将使用它与正在运行的数据库实例进行通信。 使用以下代码执行此操作:

1122

Using the snippet above, the connection will be established to the default host (localhost) and port (27017). You can also specify the host and/or port using:

使用上面的代码段,将建立到默认主机( localhost )和端口( 27017 )的连接。 您还可以使用以下命令指定主机和/或端口:

11

Or just use the Mongo URI format:

或仅使用Mongo URI格式:

11

All of these calls to MongoClient will do the same thing; it just depends on how explicit you want to be in your code.

所有对MongoClient调用MongoClient将执行相同的操作; 这仅取决于您要在代码中显示的明确程度。

访问数据库 (Accessing Databases)

Once you have a connected instance of MongoClient, you can access any of the databases within that Mongo server. To specify which database you actually want to use, you can access it as an attribute:

连接MongoClient实例后,就可以访问该Mongo服务器中的任何数据库。 要指定您实际要使用的数据库,可以将其作为属性访问:

11

Or you can also use the dictionary-style access:

或者,您也可以使用字典式访问:

11

It doesn’t actually matter if your specified database has been created yet. By specifying this database name and saving data to it, you create the database automatically.

您指定的数据库是否已创建实际上并不重要。 通过指定此数据库名称并将数据保存到该数据库名称,可以自动创建数据库。

插入文件 (Inserting Documents)

Storing data in your database is as easy as calling just two lines of code. The first line specifies which you’ll be using (posts in the example below). In MongoDB terminology, a collection is a group of documents that are stored together within the database. Collections and documents are to SQL tables and rows, respectively. Retrieving a collection is as easy as getting a database.

在数据库中存储数据就像只调用两行代码一样容易。 第一行指定您将使用的 (下例中的posts )。 用MongoDB术语来说,集合是一组一起存储在数据库中的文档。 集合和文档分别 SQL表和行。 检索集合就像获取数据库一样容易。

The second line is where you actually insert the data in to the collection using the insert_one() method:

第二行是您使用insert_one()方法将数据实际插入集合中的insert_one()

1122334455667788

We can even insert many documents at a time, which is much faster than using insert_one() if you have many documents to add to the database. The method to use here is insert_many(). This method takes an array of document data:

我们甚至可以一次插入许多文档,如果要向数据库中添加许多文档,这比使用insert_one()快得多。 这里使用的方法是insert_many() 。 此方法采用文档数据数组:

11223344556677889910101111121213131414151516161717

When ran, you should see something like:

运行后,您应该会看到类似以下内容的内容:

112233445566

NOTE: Don’t worry that your ObjectIds don’t match those shown above. They are dynamically generated when you insert data and consist of a Unix epoch, machine identifier, and other unique data.

注意:不用担心您的ObjectId与上面显示的不匹配。 它们是在您插入数据时动态生成的,并且由Unix时期,机器标识符和其他唯一数据组成。

检索文件 (Retrieving Documents)

To retrieve a document, we’ll use the find_one() method. The lone argument that we’ll use here (although it supports many more) is a dictionary that contains fields to match. In our example below, we want to retrieve the post that was written by Bill:

要检索文档,我们将使用find_one()方法。 我们将在这里使用的lone参数(尽管它支持更多参数)是一个字典,其中包含要匹配的字段。 在下面的示例中,我们想要检索Bill撰写的帖子:

1122

Run this:

运行这个:

112233445566

You may have noticed that the post’s ObjectId is set under the _id key, which we can later use to uniquely identify it if needed. If we want to find more than one document, we can use the find() method. This time, let’s find all of the posts written by Scott:

您可能已经注意到,帖子的ObjectId是在_id键下设置的,以后我们可以根据需要使用它唯一地标识它。 如果要查找多个文档,可以使用find()方法。 这次,让我们找到Scott撰写的所有文章:

1122

Run:

跑:

11

The main difference here is that the document data isn’t returned directly to us as an array. Instead we get an instance of the object. This Cursor is an iterable object that contains quite a few helper methods to help you work with the data. To get each document, just iterate over the result:

这里的主要区别是文档数据不是作为数组直接返回给我们的。 相反,我们获得了对象的实例。 该Cursor是一个可迭代的对象,其中包含许多帮助方法来帮助您处理数据。 要获取每个文档,只需遍历结果即可:

1122

蒙戈引擎 (MongoEngine)

While PyMongo is very easy to use and overall a great library, it’s probably a bit too low-level for many projects out there. Put another way, you’ll have to write a lot of your own code to consistently save, retrieve, and delete objects.

虽然PyMongo非常易于使用,并且总体上是一个很棒的库,但是对于那里的许多项目来说,它可能太低级了。 换句话说,您必须编写许多自己的代码才能一致地保存,检索和删除对象。

One library that provides a higher abstraction on top of PyMongo is . MongoEngine is an object document mapper (ODM), which is roughly equivalent to a SQL-based object relational mapper (ORM). The abstraction provided by MongoEngine is class-based, so all of the models you create are classes.

一个在PyMongo之上提供更高抽象性的库是 。 MongoEngine是一个对象文档映射器(ODM),与基于SQL的对象关系映射器(ORM)大致等效。 MongoEngine提供的抽象是基于类的,因此您创建的所有模型都是类。

While quite a few Python libraries exist to help you work with MongoDB, MongoEngine is one of the better ones as it has a nice mix of features, flexibility, and community support without becoming too opinionated.

虽然存在许多Python库可以帮助您使用MongoDB,但是MongoEngine是更好的库之一,因为它很好地融合了功能,灵活性和社区支持,而不会显得太自以为是。

To install, use pip:

要安装,请使用pip

11

Once installed, we need to direct the library to connect with our running instance of Mongo. For this we will have to use the connect() function and pass the host and port of the MongoDB database to it. Within the Python shell, type:

安装完成后,我们需要引导该库与正在运行的Mongo实例连接。 为此,我们将必须使用connect()函数并将MongoDB数据库的主机和端口传递给它。 在Python Shell中,键入:

1122

Here we specify the name of our database and location. Since we’re still using the default host and port, you can omit these parameters.

在这里,我们指定数据库的名称和位置。 由于我们仍在使用默认的主机和端口,因此可以省略这些参数。

定义文件 (Defining a Document)

To set up our document object, we need to define what data we want our document object to have. Similar to many other ORMs, we’ll do this by subclassing the Document class and providing the types of data we want:

要设置我们的文档对象,我们需要定义我们希望文档对象拥有的数据。 与许多其他ORM相似,我们将通过子类化Document类并提供所需的数据类型来做到这一点:

11223344556677

NOTE: One of the more difficult tasks with database models is validating data. How do you make sure that the data you’re saving conforms to some format you need? Just because a database is said to be schema-less doesn’t mean it is schema-free.

注意:使用数据库模型更困难的任务之一是验证数据。 如何确定要保存的数据符合所需的某种格式? 仅仅因为数据库是无架构的,并不意味着它是无架构的。

In this simple model, we’ve told MongoEngine that we expect a Post instance to have a title, content, an author, and the date it was published. Now the base Document object can use that information to validate the data we provide it.

在这个简单的模型中,我们告诉MongoEngine,我们希望Post实例具有titlecontentauthor和发布date 。 现在,基本Document对象可以使用该信息来验证我们提供的数据。

So, for example, if we try to save a Post without a title then it’ll throw an Exception and let us know. We can take this even further and add more restrictions, like string length. Notice that some of the fields have a max_length parameter set. This tells the Document, as you probably guessed, to only allow a maximum string length of however many characters we specify. There are quite a few more parameters like this we can set, including:

因此,例如,如果我们尝试保存不带titlePost ,那么它将引发Exception并通知我们。 我们可以更进一步,添加更多限制,例如字符串长度。 请注意,某些字段设置了max_length参数。 您可能会猜到,这告诉Document仅允许最大字符串长度为我们指定的许多字符。 我们可以设置更多类似的参数,包括:

  • db_field: Specify a different field name
  • required: Make sure this field is set
  • default: Use the given default value if no other value is given
  • unique: Make sure no other document in the collection has the same value for this field
  • choices: Make sure the field’s value is equal to one of the values given in an array
  • db_field :指定其他字段名称
  • required :确保已设置此字段
  • default :如果没有其他值,则使用给定的默认值
  • unique :确保集合中没有其他文档对此字段具有相同的值
  • choices :确保字段的值等于数组中给出的值之一

Each field type has its own set of parameters, so be sure to for more info.

每种字段类型都有其自己的参数集,因此请务必以获取更多信息。

保存文件 (Saving Documents)

To save a document to our database, we’ll use the save() method. If the document already exists in the database, then all of the changes will be made on the atomic level to the existing document. If it doesn’t exist, however, then it will be created.

要将文档保存到我们的数据库中,我们将使用save()方法。 如果文档已经存在于数据库中,则将在原子级别对现有文档进行所有更改。 但是,如果不存在,则会创建它。

Here is an example of creating and saving a document:

这是创建和保存文档的示例:

1122334455667788991010

A few things to note about the .save() call:

有关.save()调用的几点注意事项:

  • PyMongo will perform validation when you call .save(). This means it will check the data you’re saving against the schema you declared in the class. If the schema (or a constraint) is violated, then an exception is thrown and the data is not saved.
  • Since Mongo doesn’t support true transactions, there is no way to “roll back” the .save() call like you can in SQL databases. Although you can get close to performing transactions with , they still don’t support rollbacks.
  • 当您调用.save()时,PyMongo将执行验证。 这意味着它将根据您在类中声明的架构检查要保存的数据。 如果违反了架构(或约束),那么将引发异常,并且不会保存数据。
  • 由于Mongo不支持真正的事务,因此无法像SQL数据库一样“回滚” .save()调用。 尽管您可以通过来接近执行事务,但它们仍然不支持回滚。

What happens when you leave off the title?

忘记title怎样?

1122

You should see the following exception:

您应该看到以下异常:

112233

面向对象的功能 (Object Oriented Features)

With MongoEngine being object oriented, you can also add methods to your subclassed document. Consider the following example where a function is used to modify the default queryset (which returns all objects of the collection). By using this, we can apply a default filter to the class and get only the desired objects:

通过将MongoEngine面向对象,您还可以将方法添加到子类文档中。 考虑以下示例,其中使用一个函数来修改默认查询集(该查询集返回集合的所有对象)。 通过使用此方法,我们可以将默认过滤器应用于该类并仅获取所需的对象:

11223344556677

参考其他文件 (Referencing Other Documents)

You can also use the ReferenceField object to create a reference from one document to another. MongoEngine handles the lazy de-referencing automatically upon access, which is more robust and less error-prone than having to remember to do it yourself everywhere in your code. An example:

您还可以使用ReferenceField对象创建从一个文档到另一个文档的引用。 MongoEngine会在访问时自动处理延迟取消引用,这比必须记住自己在代码中的任何地方进行操作更加健壮且不易出错。 一个例子:

11223344556677

In the code above, using a document reference, we can easily find the author of the first post.

在上面的代码中,使用文档参考,我们可以轻松找到第一篇文章的作者。

There are quite a few more field classes (and parameters) than what we introduced here, so be sure to check out the for more info.

字段类(和参数)比我们在这里介绍的要多得多,因此请务必查看 ” 获取更多信息。

From all of these examples you should be able to see that MongoEngine is well suited to manage your database objects for just about any type of application. The features available at the developer’s disposal make it incredibly easy to create an efficient and scalable program. In case you’re looking for more help related to MongoEngine, be sure to check out their comprehensive .

从所有这些示例中,您应该可以看出MongoEngine非常适合用于管理几乎所有类型的应用程序的数据库对象。 开发人员可以使用的功能使创建高效且可扩展的程序变得异常容易。 如果您正在寻找与MongoEngine相关的更多帮助,请务必查看其全面的 。

结论 (Conclusion)

With Python being a high-level, highly scalable, modern language, it needs a database (and driver) that can keep up to its potential, which is why MongoDB is such a good fit.

由于Python是一种高级,高度可扩展的现代语言,因此它需要一个能够保持其潜力的数据库(和驱动程序),这就是MongoDB非常适合的原因。

We saw in this article how we can exploit the strengths of MongoDB to our advantage and build a highly flexible and scalable application. Feel free to let us know your thoughts in the comments section!

我们在本文中看到了如何利用MongoDB的优势来发挥优势并构建高度灵活和可扩展的应用程序。 欢迎在评论部分让我们知道您的想法!

翻译自:

转载地址:http://evqwd.baihongyu.com/

你可能感兴趣的文章
hdu 1251 统计难题
查看>>
java中关于String 类型数据 的存储方式
查看>>
javascript中的with语句
查看>>
常用设计模式:装饰者模式
查看>>
python接口自动化--get请求
查看>>
ajax 上传文件
查看>>
lintcode-easy-Flatten Binary Tree to Linked List
查看>>
从远程队列中读取消息
查看>>
typescript 接口的新认识
查看>>
java常见面试题及三大框架面试
查看>>
懒惰的肥兔博文导读
查看>>
[db] mongodb 存取修改简单小实例
查看>>
面试百题003——求子数组的最大和
查看>>
jq.validate 自定义验证两个日期
查看>>
公布一个以前写的随机数生成的方法
查看>>
AtCoder Regular Contest 077 被虐记&题解
查看>>
禁止ios10双指缩放
查看>>
LUOGU P1505 [国家集训队]旅游 (树链剖分+线段树)
查看>>
BZOJ 3509: [CodeChef] COUNTARI(fft+分块)
查看>>
flask源码解读05: Context(AppContext, RequestContext)
查看>>