Home Database Mysql Tutorial MongoDB基础理念及操作初探

MongoDB基础理念及操作初探

Jun 07, 2016 pm 04:47 PM
mongodb o database

MongoDB是一个高性能,开源,无模式的文档型数据库,它在许多场景下可用于替代传统的关系型数据库或键/值存储方式

MongoDB是一个高性能,开源,无模式的文档型数据库,它在许多场景下可用于替代传统的关系型数据库或键/值存储方式

基础概念:

NoSQL

泛指非关系型的数据库。随着互联网web2.0网站的兴起,传统的关系数据库在应付web2.0网站,特别是超大规模和高并发的SNS类型的web2.0纯动态网站已经显得力不从心,暴露了很多难以克服的问题,而非关系型的数据库则由于其本身的特点得到了非常迅速的发展。

------------------------------------------------------------------

MongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里

相关阅读:

MongoDB备份与恢复

CentOS编译安装MongoDB

CentOS 编译安装 MongoDB与mongoDB的php扩展

CentOS 6 使用 yum 安装MongoDB及服务器端配置

Ubuntu 13.04下安装MongoDB2.4.3

如何在MongoDB中建立新数据库和集合

MongoDB入门必读(概念与实战并重)

《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF]

------------------------------------------------------------------

 

NoSQL的特点:

·分关系型

·分布式

·不提供ACID功能

 

本身常用技术特点:

·数据模型非常简单(每个记录只有单独的键

·元数据和应用数据分离

·弱一致性

其优势:

·避免不必要的复杂

对于web应用来讲,有些一致性有些多余,所以最适用于web2.0的应用场景

·高吞吐量

·高 水平扩展和低端硬件集群

·不使用关系型映射(所以使用的模型非常简单)

 

其劣势:

·功能过于简单

·没有统一的数据查询模型

 

NoSQL数据库类别:

·键值存储

·列式数据库

·文档数据库

每一行都相当于独立的文件

·图式数据库

存放的为图,有着复杂对象关系的视图,比如在社交网站存储每个用户之间的关系的时候,通常需要用这种模式进行存储

·缓存数据库系统:不具备存储能力,完全用来提供缓存,比如Memcached、Redis

 

·CAP Therorem

C,A模型:保证一致性和可用性 就是传统数据库-sql数据库

C,P模型:悲观加锁机制(最终一致性 )

A,,P模型:只保证可用性 和分区容忍性 比如DNS

·ACID & BASE

主要评估于系统本身基本的可用能力 软状态 以及能实现最终一致性,分布式集群中一般都使用BASE

 

而数据一致性模型分为以下几种:

·强一致性

无论更新操作在哪个副本上执行,之后的操作都能获得一致性的数据

·弱一致性

用户对某一数据更新需要一定的时间,将由一定的时间段处于不一致状态,在这段时间内为弱一致性

·最终一致性

 

数据一致性的实现技术:

·Quorum系统 NRW策略

N:总的副本数

R:完成度操作所需要读取最少副本数

W:完成写操作所需要写入最少副本数

强制一致性 R+W>N

比如 :mysql一主两从

 

最终一致性 R+W

 

两段式提交协议:2PC

分为两类节点:

·协调者进程

·参与者进程

每个事物都有可能自己去写数据,并实现持久存储,而且节点之间可以任意通信

分为两个阶段:

·请求节点

·提交阶段

每个事物的参与者进程都必须提交数据,再由协调者进程进行协调后得出最终结果才能真正意义往上提交

每个请求议案,都被列为最终议案的一部分

事物协调者将请求发送于参与者使其提交事物,于是参与者统统都提交事物(这个阶段为请求)

协调者收到请求,于是再次通知两者(参与者)使其开始提交事物(提交阶段)

协调者将所有事物进行协调处理并得出最终结果(保持最终一致性)

 

提交失败如何处理:

如果其中以个节点出现故障(不同意提交)那么所有提交事物则全部取消提交操作

 

时间戳策略:

paxos:基于选举策略来选择

 

向量时钟

 

Nosql的数据存储模型:

包含了很多种不同的技术,通常能够根据不同的机制能够把他们分为不同的流派,而最简单的分裂方式就是根据数据存储模型来进行分类

流派:

·键值存储模型:(key-value存储)只能够简单存储键值模型,而且多个键值之间不能组合使用

查找迅速

 

数据无结构,通常指被当做字符串货二进制数据

应用场景:主要实现内容缓存,处理大量数据的高访问负载,也能用户日志系统的日志写入等做内容缓存

实例:redis, Dynamo

 

·列式模型:

数据按列存储,将同一列数据存放在一起(一起可能是同一节点或同一数据集中)

优点:查找迅速因为没有特别复杂的结构模型

可扩展性强

易于实现分布式

缺点:

功能相对有限(相对sql产品来讲)

 

其应用场景:主要用于分布式存储或分布式文件系统等

实例:Bigtable,cassandra,HBase等

 

·文档模型:

数据模型:与键值型模型类似,但是vaule指向结构化数据

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

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())

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

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

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How does Go WebSocket integrate with databases? How does Go WebSocket integrate with databases? Jun 05, 2024 pm 03:18 PM

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.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

How to handle database connections and operations using C++? How to handle database connections and operations using C++? Jun 01, 2024 pm 07:24 PM

Use the DataAccessObjects (DAO) library in C++ to connect and operate the database, including establishing database connections, executing SQL queries, inserting new records and updating existing records. The specific steps are: 1. Include necessary library statements; 2. Open the database file; 3. Create a Recordset object to execute SQL queries or manipulate data; 4. Traverse the results or update records according to specific needs.

Top 10 global digital currency trading apps recommended (2025 currency trading software ranking) Top 10 global digital currency trading apps recommended (2025 currency trading software ranking) Mar 12, 2025 pm 05:48 PM

This article recommends the top ten digital currency trading apps in the world, including Binance, OKX, Huobi Global, Coinbase, Kraken, Gate.io, KuCoin, Bitfinex, Gemini and Bitstamp. These platforms have their own characteristics in terms of transaction pair quantity, transaction speed, security, compliance, user experience, etc. For example, Binance is known for its high transaction speed and extensive services, while Coinbase is more suitable for novices. Choosing a platform that suits you requires comprehensive consideration of your own needs and risk tolerance. Learn about the world's mainstream digital currency trading platforms to help you conduct digital asset trading safely and efficiently.

How to install and register the btc trading app? How to install and register the btc trading app? Feb 21, 2025 pm 07:09 PM

This article will provide a detailed introduction to how to install and register a Bitcoin trading application. The Bitcoin trading app allows users to manage and trade cryptocurrencies such as Bitcoin. The article guides users through the installation and registration process step by step, including downloading applications, creating accounts, performing identity verification, and first deposit. The goal of the article is to provide beginners with clear and easy-to-understand guidelines to help them easily enter the world of Bitcoin trading.

See all articles