Mongoengine 简明教程

MongoEngine - MongoDB

在过去十年中,NoSQL 数据库变得越来越受欢迎。在当今实时 Web 应用程序的世界中,移动设备和嵌入式设备产生了大量数据。传统的关联数据库(如 Oracle、MySQL 等)不适用于字符串。此类数据的处理过程也存在困难,因为它们具有固定和预定义的模式,且不可扩展。NoSQL 数据库拥有灵活的模式,并以分布式的方式存储在大量社区服务器上。

NoSQL databases have seen rise in popularity in the last decade. In today’s world of real time web applications, huge amount of data is being generated with mobile and embedded devices. Traditional relational databases (like Oracle, MySQL, etc.) are not suitable for strings. The processing of such data is also difficult as they have fixed and predefined schema, and are not scalable. NOSQL databases have flexible schema and are stored in distributed manner on a large number of community servers.

NoSQL 数据库根据数据的组织方式进行分类。MongoDB 是一款流行的文档存储 NoSQL 数据库。MongoDB 数据库的基本组成部分被称为文档。文档是由 JSON 格式中存储的一组键值对。在一个集合中存储了多个文档。一个集合可以看作是任何关系数据库中的一张表,而一个文档则是表中的一行。不过需要指出的是,由于 MongoDB 无模式,一个集合中每份文档中的键值对数量不一定相同。

NOSQL databases are classified on the basis of organization of data. MongoDB is a popular Document Store NOSQL database. Fundamental constituent of a MongoDB database is called a document. A document is a collection of key-value pairs stored in JSON format. More than one documents are stored in a collection. A collection can be considered as analogous to a table in any relational database, and a Document as row in a table. However, it should be noted that since MongoDB is schema less, number of key-value pairs in each document of a Collection need not be the same.

MongoDB 是由 MongoDB Inc. 开发的。它是一个通用的、基于分布式文档的数据库。它提供企业版和社区版。可在 https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2012plus-4.2.6-signed.msi 下载适用于 Windows 操作系统的最新版本社区版。

MongoDB is developed by MongoDB Inc. It is a general-purpose, distributed document based database. It is available in enterprise as well as community edition. Latest version of Community version for Windows operating system can be downloaded from https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2012plus-4.2.6-signed.msi.

在您选择的文件夹中安装 MongoDB,并使用以下命令启动服务器 −

Install MongoDB in a folder of your choice and start the server with the following command−

D:\mongodb\bin>mongod

服务器现已准备好接受端口 27017 上的传入连接请求。MongoDB 数据库存储在 bin/data 目录中。可以通过上述命令中的 –dbpath 选项更改此位置。

Server is now ready for incoming connection requests at port 27017. MongoDB databases are stored in bin/data directory. This location can be changed by –dbpath option in above command.

在另一个命令终端中,使用以下命令启动 MongoDB 控制台 −

In another command terminal, start MongoDB console with the following command −

D:\mongodb\bin>mongo

MongoDB 提示类似于我们在 MySQL 或 SQLite 终端中通常看到的提示。所有数据库操作(例如创建数据库、插入文档、更新和删除以及检索文档)都可以在控制台中完成。

MongoDB prompt is similar to what we normally see in MySQL or SQLite terminal. All database operations such as creating database, inserting a document, updating and deleting as well as retrieval of documents can be done from within the console.

E:\mongodb\bin>mongo
MongoDB shell version v4.0.6
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("0d848b11-acf7-4d30-83df-242d1d7fa693") }
MongoDB server version: 4.0.6
---
>

正在使用的默认数据库为 test。

Default database in use is test.

> db
Test

使用 'use' 命令可将任何其他数据库设置成当前数据库。如果指定的数据库不存在,则会创建新的数据库。

With 'use' command any other database is set as current. If the named database does not exist, new one is created.

> use mydb
switched to db mydb

请参阅我们在 https://www.tutorialspoint.com/mongodb/index.htm 上的关于 MongoDB 的详细教程。

Please refer to our detailed tutorial on MongoDB at https://www.tutorialspoint.com/mongodb/index.htm.