Arangodb 简明教程
ArangoDB - Data Models and Modeling
在本章中,我们将重点关注以下主题 -
In this chapter, we will focus on the following topics −
-
Database Interaction
-
Data Model
-
Data Retrieval
ArangoDB 支持基于文档的数据模型和基于图的数据模型。让我们首先描述基于文档的数据模型。
ArangoDB supports document based data model as well as graph based data model. Let us first describe the document based data model.
ArangoDB 的文档与 JSON 格式非常相似。一个文档中包含零个或多个属性,每个属性都附加一个值。值可以是原子类型,例如数字、布尔值或空,文字字符串或复合数据类型,例如嵌入式文档/对象或数组。数组或子对象可能由这些数据类型组成,这意味着单个文档可以表示非平凡的数据结构。
ArangoDB’s documents closely resemble the JSON format. Zero or more attributes are contained in a document, and a value attached with each attribute. A value is either of an atomic type, such as a number, Boolean or null, literal string, or of a compound data type, such as embedded document/object or an array. Arrays or sub-objects may consist of these data types, which implies that a single document can represent non-trivial data structures.
在层次结构中,文档被组织成集合,这些集合可能不包含文档(理论上)或包含多个文档。人们可以将文档与行进行比较,将集合与表进行比较(此处表和行指关系数据库管理系统 - RDBMS 的那些)。
Further in hierarchy, documents are arranged into collections, which may contain no documents (in theory) or more than one document. One can compare documents to rows and collections to tables (Here tables and rows refer to those of relational database management systems - RDBMS).
但在 RDBMS 中,定义列是将记录存储到表中的先决条件,称这些定义为模式。然而,作为新特性,ArangoDB 是无模式的——在先验中没有任何理由指定文档会具有的属性。
But, in RDBMS, defining columns is a prerequisite to store records into a table, calling these definitions schemas. However, as a novel feature, ArangoDB is schema-less – there is no a priori reason to specify what attributes the document will have.
而且,与 RDBMS 不同的是,每个文档都可以采用与其他文档完全不同的方式来构建。这些文档可以保存在一个集合中。实际上,集合中的文档之间可能存在一些共同特征,但是数据库系统(即 ArangoDB 本身)不会把你绑定到特定的数据结构上。
And unlike RDBMS, each document can be structured in a completely different way from another document. These documents can be saved together in one single collection. Practically, common characteristics may exist among documents in the collection, however the database system, i.e., ArangoDB itself, does not bind you to a particular data structure.
现在,我们将尝试理解 ArangoDB 的 [ graph data model ],它需要两种集合——第一种是文档集合(在群论语言中称为顶点集合),第二种是边缘集合。这两类之间有一个微妙的区别。边缘集合也会存储文档,但它们的特征是包含两个唯一属性 _from 和 _to ,用于在文档之间创建关系。实际上,一个文档(边)会链接两个文档(顶点),这两个文档都分别存储在各自的集合中。此架构源于标签有向图的图论概念,它排除了不仅可以有标签,而且也可以是完整 JSON(像文档一样)的边缘。
Now we will try to understand ArangoDB’s [graph data model], which requires two kinds of collections — the first is the document collections (known as vertices collections in group-theoretic language), the second is the edge collections. There is a subtle difference between these two types. Edge collections also store documents, but they are characterized by including two unique attributes, _from and _to for creating relations between documents. In practice, a document (read edge) links two documents (read vertices), both stored in their respective collections. This architecture is derived from the graph-theoretic concept of a labeled, directed graph, excluding edges that can have not only labels, but can be a complete JSON like document in itself.
为了计算新的数据、删除文档或对文档进行控制,会用到查询,它依给定条件选择或过滤文档。查询可以像“示例查询”那么简单,也可以像“联接”那么复杂。查询都用 AQL(ArangoDB 查询语言)编写。
To compute fresh data, delete documents or to manipulate them, queries are used, which select or filter documents as per the given criteria. Either being simple as an “example query” or being as complex as “joins”, queries are coded in AQL - ArangoDB Query Language.