MongoDB简介

MongeDB是一个开源的文档数据库(Document Database),旨在将数据作为类 JSON 文档存储和查询。文档数据库让开发人员可以使用他们在其应用程序代码中使用的相同文档模型格式,更轻松地在数据库中存储和查询数据。文档和文档数据库的灵活、半结构化和层级性质允许它们随应用程序的需求而变化。

document database是内容管理应用程序的一个绝佳选择,例如博客和视频平台。通过文档数据库,应用程序跟踪的每个实体都可以存储为单个文档。 另一个使用案例是,document database存储目录信息方面高效且有效。 例如,在电子商务应用程序中,不同的产品通常具有不同数量的属性。在关系数据库中管理数千个属性效率较低,并且阅读性能会受到影响。使用文档数据库,可以在单个文档中描述每个产品的属性,以方便管理和加快阅读速度。更改一个产品的属性不会影响其他产品。

MongoDB的概念包括:
database,collection(等同于table),document(等同于row),field(等同于column)。

首先来看看MongoDB中一行数据的样子(也就是document)。注意:
1,如果没有指定_id,则mongoDB生成一个objectId作为_id。
2,早期document的类型是JSON-like,又称BSON(区别就是key不使用“”)。后来开始支持JSON。

{
_id: ObjectId(“509a8fb2f3f4948bd2f983a0”),
user_id: “abc123”,
age: 55,
status: ‘A’ ,
tag:{
blog:“lovely girl”,
facebook:“pretty girl”
}
}

事务
早期仅支持一个document operation的原子性,现在MongoDB支持完全的ACID操作。
In MongoDB, an operation on a single document is atomic. Because you can use embedded documents and arrays to capture relationships between data in a single document structure instead of normalizing across multiple documents and collections, this single-document atomicity obviates the need for multi-document transactions for many practical use cases.

For situations that require atomicity of reads and writes to multiple documents (in a single or multiple collections), MongoDB supports multi-document transactions. With distributed transactions, transactions can be used across multiple operations, collections, databases, documents, and shards.

外键和Join

早期不支持join,并建议用nested field的形式来存储join的内容。
现在MongoDB does support join.

索引

MongoDB使用索引来提高查询效率。索引使用的数据结构和关系型数据库相同,也是B-tree的。

Aggregation
MongoDB支持大部分SQL中的聚合操作。如group by,having,sum,count等。

你可能感兴趣的:(NoSQL数据库)