1

我对 OrientDB 世界很陌生,并渴望在生产中使用 OrientDB/OrientJS。

阅读相关文档后,我对在 OrientJS 中使用“集群”功能感到困惑。特征涉及“ CREATE CLASS”、“ ALTER CLASS ADDCLUSTER”、“ create records in the specified cluster”、“ select records from clusters”、“ LiveQuery”等。

请对这些问题有所了解。

4

2 回答 2

1

我创建了一个数据库来尝试您关于集群功能的请求。

var OrientDB = require('orientjs');

var server = OrientDB({
    host: 'localhost',
    port: 2424,
    username: 'root',
    password: 'root'
});

var db = server.use({
    name: 'OrientJStest',
    username: 'root',
    password: 'root'
});
  1. 创建类(Place):

    db.class.create('Place', 'V')
        .then(function (Class) {
            console.log("Created class "+Class.name);
    });
    

    输出

    Created class Place
    
  2. 创建属性 ( Name):

    db.class.get('Place')
        .then(function (Class) {
        console.log('Class: ' + Class.name);
        Class.property.create({
            name: 'name',
            type: 'String'
        })
        .then(function (newProp) {
            console.log('Property created: ' + newProp.name);
        });
    });
    

    输出:

    Class: Place
    Property created: name
    
  3. 改变类 ( Place) 加法器 ( place2):

    db.query('ALTER CLASS Place ADDCLUSTER place2')
        .then(function (cluster) {
            console.log(cluster);
    });
    
  4. 插入集群 ( place):

    db.insert().into('cluster:place')
        .set({name:'London'}).all()
        .then(function (record) {
            console.log('Created record: ',record);
    });
    

    输出:

    Created record:  [ { '@type': 'd',
        '@class': 'Place',
        name: 'London',
        '@rid': { [String: '#15:0'] cluster: 15, position: 0 },
        '@version': 1 } ]
    
  5. 插入集群 ( place2):

    db.insert().into('cluster:place2')
        .set({name:'Manchester'}).all()
        .then(function (record) {
            console.log('Created record: ',record);
    });
    

    输出:

    Created record:  [ { '@type': 'd',
        '@class': 'Place',
        name: 'Manchester',
        '@rid': { [String: '#16:0'] cluster: 16, position: 0 },
        '@version': 1 } ]
    
  6. 从集群中选择 ( place):

    db.select().from('cluster:place').all()
        .then(function (vertex) {
            console.log('Vertexes found: ',vertex);
    });
    

    输出:

    Vertexes found:  [ { '@type': 'd',
        '@class': 'Place',
        name: 'London',
        '@rid': { [String: '#15:0'] cluster: 15, position: 0 },
        '@version': 1 } ]
    
  7. 从集群中选择 ( place2):

    db.select().from('cluster:place2').all()
        .then(function (vertex) {
            console.log('Vertexes found: ',vertex);
    });
    

    输出:

    Vertexes found:  [ { '@type': 'd',
        '@class': 'Place',
        name: 'Manchester',
        '@rid': { [String: '#16:0'] cluster: 16, position: 0 },
        '@version': 1 } ]
    
  8. 从所有类别中选择Place

    db.select().from('Place').all()
        .then(function (vertex) {
            console.log('Vertexes found: ',vertex);
    });
    

    输出:

    Vertexes found:  [ { '@type': 'd',
        '@class': 'Place',
        name: 'London',
        '@rid': { [String: '#15:0'] cluster: 15, position: 0 },
        '@version': 1 },
      { '@type': 'd',
        '@class': 'Place',
        name: 'Manchester',
        '@rid': { [String: '#16:0'] cluster: 16, position: 0 },
        '@version': 1 } ]
    

如您所见,顶点在同一个类中,但在不同的簇中。

希望能帮助到你

于 2016-04-13T07:29:58.137 回答
0

根据文档,集群“是一种非常通用的分组记录方式”,默认类和集群之间的关系是 1:1,然后为每个创建的类创建其相关集群。您始终可以指定将新记录/文档/顶点/边放在哪个集群中。因此,让我们为每个字母创建 1 个簇并将其添加到类中。例子:

create cluster employee_a // cluster id = 12 alter class Employee addcluster 12

create cluster employee_b // cluster id = 13 alter class Employee addcluster 13

create cluster employee_c // cluster id = 14 alter class Employee addcluster 14

如何管理集群取决于您的需求。然后根据您选择的策略,将相应地保存新顶点(例如:使用“循环法”将 1 个顶点保存在集群 12 中,1 个顶点保存在集群 13 中,1 个顶点保存在集群 14 中。

要获取特定集群中存在的数据:从 Cluster:12 中选择

于 2016-03-14T09:52:26.367 回答