Arangodb 简明教程
ArangoDB - Example Case Scenarios
在本章中,我们将考虑两种示例场景。这些示例更容易理解,将帮助我们了解 ArangoDB 功能的工作方式。
In this chapter, we will consider two example scenarios. These examples are easier to comprehend and will help us understand the way the ArangoDB functionality works.
为了演示 API,ArangoDB 预先加载了一组易于理解的图。在你的 ArangoDB 中创建这些图的实例有两种方法 −
To demonstrate the APIs, ArangoDB comes preloaded with a set of easily understandable graphs. There are two methods to create instances of these graphs in your ArangoDB −
-
Add Example tab in the create graph window in the web interface,
-
or load the module @arangodb/graph-examples/example-graph in Arangosh.
首先,让我们借助 Web 界面加载一个图。为此,启动 Web 界面并单击 graphs 选项卡。
To start with, let us load a graph with the help of web interface. For that, launch the web interface and click on the graphs tab.
显示 Create Graph 对话框。向导包含两个选项卡 – Examples 和 Graph 。 Graph 选项卡默认打开;假设我们要创建一个新图,它会询问图的名称和其他定义。
The Create Graph dialog box appears. The Wizard contains two tabs – Examples and Graph. The Graph tab is open by default; supposing we want to create a new graph, it will ask for the name and other definitions for the graph.
现在,我们将上传已创建的图形。为此,我们将选择 Examples 选项卡。
Now, we will upload the already created graph. For this, we will select the Examples tab.
我们可以看到三个示例图形。选择 Knows_Graph 并单击绿色按钮创建。
We can see the three example graphs. Select the Knows_Graph and click on the green button Create.
创建好后,可以在用于创建以下图片的 Web 界面中检查它们。
Once you have created them, you can inspect them in the web interface - which was used to create the pictures below.
The Knows_Graph
现在让我们看看 Knows_Graph 如何工作。选择 Knows_Graph,它将获取图形数据。
Let us now see how the Knows_Graph works. Select the Knows_Graph, and it will fetch the graph data.
Knows_Graph 由一个通过一个边集合 knows 连接的顶点集合 persons 组成。它将包含五个人 Alice、Bob、Charlie、Dave 和 Eve 作为顶点。我们将拥有以下定向关系
The Knows_Graph consists of one vertex collection persons connected via one edge collection knows. It will contain five persons Alice, Bob, Charlie, Dave and Eve as vertices. We will have the following directed relations
Alice knows Bob
Bob knows Charlie
Bob knows Dave
Eve knows Alice
Eve knows Bob
如果你单击一个节点(顶点),比如“bob”,它将显示 ID(人物/bob)属性名称。
If you click a node (vertex), say ‘bob’, it will show the ID (persons/bob) attribute name.
如果单击任何边,它将显示 ID(knows/4590)属性。
And on clicking any of the edge, it will show the ID (knows/4590) attributes.
这就是创建它的方式,即检查其顶点和边。
This is how we create it, inspect its vertices and edges.
让我们再添加一个图形,这次使用 Arangosh。为此,我们需要在 ArangoDB 配置文件中包含另一个端点。
Let us add another graph, this time using Arangosh. For that, we need to include another endpoint in the ArangoDB configuration file.
How to Add Multiple Endpoints
打开配置文件 -
Open the configuration file −
# vim /etc/arangodb3/arangod.conf
添加另一个端点,如下面的终端屏幕截图所示。
Add another endpoint as shown in the terminal screenshot below.
重新启动 ArangoDB -
Restart the ArangoDB −
# service arangodb3 restart
启动 Arangosh -
Launch the Arangosh −
# arangosh
Please specify a password:
_
__ _ _ __ __ _ _ __ __ _ ___ ___| |__
/ _` | '__/ _` | '_ \ / _` |/ _ \/ __| '_ \
| (_| | | | (_| | | | | (_| | (_) \__ \ | | |
\__,_|_| \__,_|_| |_|\__, |\___/|___/_| |_|
|___/
arangosh (ArangoDB 3.1.27 [linux] 64bit, using VPack 0.1.30, ICU 54.1, V8
5.0.71.39, OpenSSL 1.0.2g 1 Mar 2016)
Copyright (c) ArangoDB GmbH
Pretty printing values.
Connected to ArangoDB 'http+tcp://127.0.0.1:8529' version: 3.1.27
[server], database: '_system', username: 'root'
Please note that a new minor version '3.2.2' is available
Type 'tutorial' for a tutorial or 'help' to see common examples
127.0.0.1:8529@_system>
The Social_Graph
现在让我们了解一下什么是 Social_Graph 以及它是如何工作的。该图形展示了一组人员及其关系 -
Let us now understand what a Social_Graph is and how it works. The graph shows a set of persons and their relations −
此示例具有女性和男性作为两个顶点集合中的顶点 - 女性和男性。边是其在连接边集合中的连接。我们已经描述了如何使用 Arangosh 创建此图形。读者可以像我们对 Knows_Graph 所做的那样对其进行研究并探索其属性。
This example has female and male persons as vertices in two vertex collections - female and male. The edges are their connections in the relation edge collection. We have described how to create this graph using Arangosh. The reader can work around it and explore its attributes, as we did with the Knows_Graph.