MongoDB入门简介
MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。他支持的数据结构非
一、基本概念
MongoDB 是一个高性能,开源,无模式的文档型数据库,是当前NoSQL 数据库产品中最热门的一种。它在许多场景下可用于替代传统的关系型数据库或键/值存储方式,MongoDB 使用C++开发。MongoDB 的官方网站地址是:,大家可以在此获得更详细的信息。
MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。他支持的数据结构非常松散,是类似json 的bjson 格式,因此可以存储比较复杂的数据类型。MongoDB 最大的特点是他支持的查询语言非常强大,其语法有点类似于面向对象的查询语言,几乎可以实现类似关系数据库单表查询的绝大部分功能,而且还支持对数据建立索引。它是一个面向集合的,模式自由的文档型数据库。
二、对比
MongoDB
关系型数据库
数据存储
面向集合
面向关系表
数据结构
模式自由
二维表关系模式
事务
不支持
支持
大型数据(视频)
很好
一般
大数据量查询(千万条以上)
很好
较差
数据库维护
相对简单
相对复杂
数据及表关系、结构浏览
困难
简单
数据安全性
较差
很好
分布式
很好
一般
查询
非常灵活
非常强大
主外键关联
不支持
支持
索引
支持
支持
存储过程
支持
支持
三、对比说明
1. 数据存储
MongoDB是面向集合(collection)的,集合中又包含多个文档(document),并支持对象型数据的存储。其中集合和文档的概念,在关系型数据库中类似于表(table)和元组(row:也就是所谓的一行数据)。另外MongoDB是以bson形式存储,而关系型数据库是以二维关系形式存储。
2. 数据结构
MongoDB对数据结构的支持非常灵活,从横向到纵向的支持都很好,比如下面的数据都能存储在同一个集合中:
① {“name”: “wangwu”, “age”: 25}
② {“name”: “lisi”}
③ {“state”: “激活”, “remark”: “无”}
④ {“name”: 6, “age”: “你猜”}
从上面的例子我们能看出,横向方面,支持字段的动态增减(如①和②),从纵向方面,支持字段数据类型混合存储(如①和④)。而在关系型数据库中这种方式的存储是绝对达不到的。
3. 事务
MongoDB本身不支持事务处理,只能通过程序代码来保证。
4. 大型数据
MongoDB不仅支持结构化数据,还支持非结构化数据存储(音频、视频、文档、XML、HTML等),而关系型数据库虽然支持大型数据(如视频)的存储,但是不管从存储效率上还是从获取速度上都不及MongoDB,MongoDB可采用高效的二进制来存储大型数据。
5. 大型数据量查询
MongoDB对于上千万条以上的数据,在查询速度上非常快。而这点却是关系型数据库中的一大痛处。
6. 数据库维护
MongoDB在数据库备份和还原以及数据的导入导出的操作上是非常简单的,通过简单的命令即可完成,还支持主-从模式及服务器之间的相互复制。复制的主要目标是提供冗余及自动故障转移,而关系型数据库在操作上相对复杂一些,上手难一些。
7. 数据及表关系、结构浏览
MongoDB因为没什么特别好的GUI客户端,所以在数据浏览和表关系、结构浏览上是非常困难和笨拙的,关系型数据库在这方面上优势明显。
8. 数据安全性
MongoDB在数据安全方面比较差,如果稍有不慎或操作不当,很容易造成数据丢失或数据错误,因此在数据维护和操作上,要非常小心。而关系型数据库在这方面上的担心却要少很多。
9. 分布式
MongoDB非常适合由数十或数百台服务器组成的数据库。支持自动分片以支持云级别的伸缩性。其中自动分片功能支持水平的数据库集群,可动态添加额外的机器。关系型数据库在分布式的支持和操作上都要困难些、发杂些。
10. 查询
MongoDB的查询语句与关系型的sql语句有着很大的不同,或者说是两种风格,二者表现都很不错,MongoDB主要体现在灵活易用上,而sql则体现在功能全面强大上。
11. 主外键关联
MongoDB不支持主外键关联,也没有“约束”的概念。
12. 索引
MongoDB同样支持索引
13. 存储过程
MongoDB同样也支持存储过程
四、总结
通过以上对比,我们可以看出MongoDB是以牺牲安全、事务、结构来换取简单、高效、灵活的,所以关系型也好非关系型也好都有他们适用的场合,非关系型数据库的出现,为我们多提供了一条选择的道路,从而在数据维护和存储上给予了我们很大的帮助,让我们在软件开发上能更加得心应手,因此传统保守关系型数据库观念的人们,可以试试体验下非关系型数据库,也许你一下就会迷上他,在关系型数据库大行其道今天,掌握好一门非关系型数据库对你未来的发展也是非常有利的。
那么关于MongoDB的入门简介就先到这里,笔者今后会对MongoDB具体的内容进行较为系统的总结和介绍,,希望能帮助需要用到的朋友。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

Analysis of the basic principles of the MySQL database management system MySQL is a commonly used relational database management system that uses structured query language (SQL) for data storage and management. This article will introduce the basic principles of the MySQL database management system, including database creation, data table design, data addition, deletion, modification, and other operations, and provide specific code examples. 1. Database Creation In MySQL, you first need to create a database instance to store data. The following code can create a file named "my

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u

How to integrate GoWebSocket with a database: Set up a database connection: Use the database/sql package to connect to the database. Store WebSocket messages to the database: Use the INSERT statement to insert the message into the database. Retrieve WebSocket messages from the database: Use the SELECT statement to retrieve messages from the database.
