MongoDB小结
前言 导师让我看一些NoSQL资料,于是目标锁定了MongoDB,至于为什么,很简单,发现了一些不错的资料。看了一些资料,有一些想法或者读后感吧,记下来,以备回忆。 简介 MongoDB是面向集合、模式自由的文档型数据库。 面向集合(collection),文档(document)而
前言
导师让我看一些NoSQL资料,于是目标锁定了MongoDB,至于为什么,很简单,发现了一些不错的资料。看了一些资料,有一些想法或者读后感吧,记下来,以备回忆。
简介MongoDB是面向集合、模式自由的文档型数据库。
面向集合(collection),文档(document)而不是面向表(table),行(row)。文档型数据库是指数据库里面的数据库格式是BSON,与Json有些类似。MongoDB只是NoSQL的一种,那么为什么要用非关系型数据库呢?
逻辑结构和存储结构逻辑结构:
关系型数据库:一个数据库实例包含多个database,一个database包含多个table,一个table包括多个rows。
MongoDB:一个MongoDB实例包含多个database,一个database包括多个collection,一个collection包括多个document。
存储结构:
关系型数据库:创建一个普通数据库生成两个文件:.mdf,.ldf。
MongoDB: 创建一个普通数据库生成两个文件.ns,.0文件。
此文详细介绍MongoDB数据文件内部结构以及
应用MongoDB自带交互式Javascript Shell,用来对MongoDB进行操作和管理,而且许多MongoDB爱好者也写了许多GUI MongoDB管理软件。MongoDB Shell相较于MongoDB GUIs更底层一些,封闭的更少些,因此更灵活,也更能了解原理,学起来也不是很难。
博客园的一线码农写了一个MongoDB系列很不错,里面介绍了MongoDB 的CURD操作,聚合函数,索引等相关知识。
架构
先知道what,再知道how,最后还得知道why。
介绍的很好。
1. Replica Sets 副本集
即MongoDB在多个服务器上备份数据。有一个primary DB,用户只能向primary DB写入数据,网站空间,但是可以从多个服务器读取数据库,从而可以实现读写分离。而Primary DB和 Secondary DB之间保持着心跳同步检测,保持数据库的一致性。当Primary DB宕机,有仲裁服务器会从Secondary 中选出一个来充当 Primary DB。
2. Auto-Sharding 自动分片
如果一个数据太大,磁盘吃紧,美国空间,需要对数据进行分片。
3.Auto-Sharding + Replica Sets
如此,不但可以解决海量存储和动态扩容问题,而且还可以实现高可靠,高并发。
每个Shard都是集群,
Shard1在三个服务器上都存在,可以提高可靠性,容错能力,备份恢复能力。
config在三个服务器上,也是同理,为了可靠的保存分片的元数据。
mongos在3个服务器上,可实现负载平衡,提高客户端接入性能。
步骤:客户端发起请求,有3个路由进程之一接收并解析命令,然后根据config服务器记录的分片元数据来确定需要接收客户端命令的分片。
服务器的具体配置可以参考 一线码农系列
MongoDB驱动在实际编程中,你当然可以使用process调用cmd命令来操作和管理MongoDB,但是太麻烦了,还是下载驱动方便方便,MongoDB驱动多着,当然会有C#,有官方,也有非官方的。 ?
优劣势优劣势自然是和关系型数据库对比了
参考MongoDB调查总结
MongoDB 身上的优势和劣势
自我总结学起来挺轻松的,也许接触的还不深,没有经过大型项目实战,但是学着一直有种和充实的感觉,那就是我知道为什么会这样,也许是开源的原因吧。NoSQL和关系型数据库各有优势,并立共存,香港虚拟主机,适用于不同的项目中。比如,Mongo不支持事务,对于银行转账之类的自然不适用;但是在web2.0时代,NoSQL的角色愈来愈重要了,NoSQL的优势也是为web2.0而生的。
参考资料1. NoSQLFan MongoDB资料汇总专题 略显杂乱
2. 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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

.NET 4.0 is used to create a variety of applications and it provides application developers with rich features including: object-oriented programming, flexibility, powerful architecture, cloud computing integration, performance optimization, extensive libraries, security, Scalability, data access, and mobile development support.

This article introduces how to configure MongoDB on Debian system to achieve automatic expansion. The main steps include setting up the MongoDB replica set and disk space monitoring. 1. MongoDB installation First, make sure that MongoDB is installed on the Debian system. Install using the following command: sudoaptupdatesudoaptinstall-ymongodb-org 2. Configuring MongoDB replica set MongoDB replica set ensures high availability and data redundancy, which is the basis for achieving automatic capacity expansion. Start MongoDB service: sudosystemctlstartmongodsudosys

When developing an e-commerce website, I encountered a difficult problem: how to provide users with personalized product recommendations. Initially, I tried some simple recommendation algorithms, but the results were not ideal, and user satisfaction was also affected. In order to improve the accuracy and efficiency of the recommendation system, I decided to adopt a more professional solution. Finally, I installed andres-montanez/recommendations-bundle through Composer, which not only solved my problem, but also greatly improved the performance of the recommendation system. You can learn composer through the following address:

This article describes how to build a highly available MongoDB database on a Debian system. We will explore multiple ways to ensure data security and services continue to operate. Key strategy: ReplicaSet: ReplicaSet: Use replicasets to achieve data redundancy and automatic failover. When a master node fails, the replica set will automatically elect a new master node to ensure the continuous availability of the service. Data backup and recovery: Regularly use the mongodump command to backup the database and formulate effective recovery strategies to deal with the risk of data loss. Monitoring and Alarms: Deploy monitoring tools (such as Prometheus, Grafana) to monitor the running status of MongoDB in real time, and

It is impossible to view MongoDB password directly through Navicat because it is stored as hash values. How to retrieve lost passwords: 1. Reset passwords; 2. Check configuration files (may contain hash values); 3. Check codes (may hardcode passwords).

Detailed explanation of MongoDB efficient backup strategy under CentOS system This article will introduce in detail the various strategies for implementing MongoDB backup on CentOS system to ensure data security and business continuity. We will cover manual backups, timed backups, automated script backups, and backup methods in Docker container environments, and provide best practices for backup file management. Manual backup: Use the mongodump command to perform manual full backup, for example: mongodump-hlocalhost:27017-u username-p password-d database name-o/backup directory This command will export the data and metadata of the specified database to the specified backup directory.

GitLab Database Deployment Guide on CentOS System Selecting the right database is a key step in successfully deploying GitLab. GitLab is compatible with a variety of databases, including MySQL, PostgreSQL, and MongoDB. This article will explain in detail how to select and configure these databases. Database selection recommendation MySQL: a widely used relational database management system (RDBMS), with stable performance and suitable for most GitLab deployment scenarios. PostgreSQL: Powerful open source RDBMS, supports complex queries and advanced features, suitable for handling large data sets. MongoDB: Popular NoSQL database, good at handling sea

Encrypting MongoDB database on a Debian system requires following the following steps: Step 1: Install MongoDB First, make sure your Debian system has MongoDB installed. If not, please refer to the official MongoDB document for installation: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/Step 2: Generate the encryption key file Create a file containing the encryption key and set the correct permissions: ddif=/dev/urandomof=/etc/mongodb-keyfilebs=512
