Mongoengine 简明教程
MongoEngine - MongoDB Compass
MongoDB 还开发了一款用于处理 MongoDB 数据库的 GUI 工具。它被称为 MongoDB Compass。这是一款无需手动编写查询即可执行所有 CRUD 操作的便利工具。它有助于执行诸多活动,如索引编制、文档验证等。
MongoDB has also developed a GUI tool for handling MongoDB databases. It is called MongoDB Compass. It is a convenient tool for performing all CRUD operations without manually writing queries. It helps in many activities such as indexing, document validation, etc.
可从 https://www.mongodb.com/download-center/compass 下载 MongoDB Compass 的社区版,并启动 MongoDBCompassCommunity.exe (确保在启动 Compass 之前 MongoDB 服务器正在运行)。通过提供正确的 host 和 port 号连接到本地服务器。
Download community edition of MongoDB Compass from https://www.mongodb.com/download-center/compass and start MongoDBCompassCommunity.exe (Ensure that MongoDB server is running before starting Compass). Connect to the local server by giving correct host and port number.

如下列出目前可用的所有数据库 −
All the databases currently available will be listed as below −

单击 + 按钮(在左面板底部显示)可创建新数据库。
Click on + button (shown at the bottom of left panel) to create new database.

从列表中选择数据库的名称,并选择一个集合,如下所示 −
Choose name of database from list and select a Collection as shown below −

您可以直接添加文档,或者从 CSV 或 JSON 文件中导入。
You can add document directly or import from CSV or JSON file.

从添加数据下拉菜单中选择插入文档。
Choose Insert Document from Add data drop down.

添加的文档将以 JSON、列表或表格形式显示 −
Documents added will be displayed in JSON, list or tabular form −

请注意,正如关系数据库中的表具有主键一样,MongoDB 数据库中的文档具有一个自动生成的特殊键称为“ _id ”。
Note that, just as a table in relational database has a primary key, document in MongoDB database has a special key called "_id" that is automatically generated.
MongoDB Inc. 为连接到 MongoDB 数据库提供了一个 Python 驱动程序。它称为 PyMongo ,其用法类似于标准 SQL 查询。
MongoDB Inc. provides a Python driver for connection with MongoDB databases. It is called PyMongo whose usage is similar to standard SQL queries.
安装 PyMongo 模块后,我们需要 MongoClient 类的对象才能与 MongoDB 服务器交互。
After installing PyMongo module, we need object of MongoClient class for interacting with MongoDB server.
<<< from pymongo import MongoClient
<<< client=MongoClient()
使用以下语句创建新数据库 −
New database is created with the following statement −
db=client.mydatabase
对该数据库上的 CRUD 操作使用 insert_one()(或 insert_many())、find()、update() 和 delete() 方法进行。PyMongo 库的详细讨论可 https://www.tutorialspoint.com/python_data_access/python_mongodb_introduction.htm 获得。
CRUD operations on this database are performed with methods such as insert_one() (or insert_many()), find(), update() and delete() methods. Detailed discussion of PyMongo library is available at https://www.tutorialspoint.com/python_data_access/python_mongodb_introduction.htm.
但是,除非将 Python 的用户定义对象转换为 MongoDB 的数据类型,否则它不能存储在数据库中。这就是我们需要 MongoEngine 库的地方。
However, Python’s user defined objects cannot be stored in database unless it is converted in MongoDB’s data types. This is where we need MongoEngine library.