Orientdb 如何使用;“集群”;OrientJS中的功能?
我刚接触OrientDB world,渴望在生产中使用OrientDB/OrientJS 阅读了相关文档后,我对在OrientJS中使用“集群”功能感到困惑。这些功能涉及“Orientdb 如何使用;“集群”;OrientJS中的功能?,orientdb,orientjs,Orientdb,Orientjs,我刚接触OrientDB world,渴望在生产中使用OrientDB/OrientJS 阅读了相关文档后,我对在OrientJS中使用“集群”功能感到困惑。这些功能涉及“创建类””、“更改类添加集群””、“在指定集群中创建记录”、“从集群中选择记录””、“Live Query”等 请解释一下这些问题。根据文档,集群“是对记录进行分组的一种非常通用的方式”,默认情况下,类和集群之间的关系为1:1,然后对于每个创建的类,由其相对集群创建。 您始终可以指定将新记录/文档/顶点/边放在哪个簇中。因此,
创建类”
”、“更改类添加集群”
”、“在指定集群中创建记录”、“从集群中选择记录”
”、“Live Query
”等
请解释一下这些问题。根据文档,集群“是对记录进行分组的一种非常通用的方式”,默认情况下,类和集群之间的关系为1:1,然后对于每个创建的类,由其相对集群创建。
您始终可以指定将新记录/文档/顶点/边放在哪个簇中。因此,让我们为每个字母创建一个簇,并将其添加到类中。例如:
创建集群员工_a//cluster id=12
alter class Employee addcluster 12
创建集群员工//集群id=13
alter类Employee addcluster 13
创建集群员工_c//cluster id=14
alter class Employee addcluster 14
如何管理集群取决于您的需要。
然后根据您选择的策略,将相应地保存新顶点(例如:使用“循环”策略,1个顶点保存在簇12中,1个顶点保存在簇13中,1个顶点保存在簇14中)
要获取特定群集中存在的数据,请执行以下操作:
从集群中选择:12我创建了一个DB来尝试您关于集群功能的请求
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'
});
创建类(Place
):
db.class.create('Place', 'V')
.then(function (Class) {
console.log("Created class "+Class.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
db.query('ALTER CLASS Place ADDCLUSTER place2')
.then(function (cluster) {
console.log(cluster);
});
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 } ]
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 } ]
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 } ]
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 } ]
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 } ]
输出:
Created class Place
创建属性(Name
):
db.class.create('Place', 'V')
.then(function (Class) {
console.log("Created class "+Class.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
db.query('ALTER CLASS Place ADDCLUSTER place2')
.then(function (cluster) {
console.log(cluster);
});
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 } ]
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 } ]
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 } ]
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 } ]
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 } ]
输出:
db.class.create('Place', 'V')
.then(function (Class) {
console.log("Created class "+Class.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
db.query('ALTER CLASS Place ADDCLUSTER place2')
.then(function (cluster) {
console.log(cluster);
});
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 } ]
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 } ]
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 } ]
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 } ]
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 } ]
更改类(Place
)添加集群(place2
):
db.class.create('Place', 'V')
.then(function (Class) {
console.log("Created class "+Class.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
db.query('ALTER CLASS Place ADDCLUSTER place2')
.then(function (cluster) {
console.log(cluster);
});
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 } ]
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 } ]
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 } ]
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 } ]
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 } ]
插入集群(place
):
db.class.create('Place', 'V')
.then(function (Class) {
console.log("Created class "+Class.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
db.query('ALTER CLASS Place ADDCLUSTER place2')
.then(function (cluster) {
console.log(cluster);
});
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 } ]
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 } ]
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 } ]
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 } ]
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 } ]
输出:
db.class.create('Place', 'V')
.then(function (Class) {
console.log("Created class "+Class.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
db.query('ALTER CLASS Place ADDCLUSTER place2')
.then(function (cluster) {
console.log(cluster);
});
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 } ]
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 } ]
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 } ]
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 } ]
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 } ]
插入集群(place2
):
db.class.create('Place', 'V')
.then(function (Class) {
console.log("Created class "+Class.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
db.query('ALTER CLASS Place ADDCLUSTER place2')
.then(function (cluster) {
console.log(cluster);
});
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 } ]
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 } ]
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 } ]
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 } ]
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 } ]
输出:
db.class.create('Place', 'V')
.then(function (Class) {
console.log("Created class "+Class.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
db.query('ALTER CLASS Place ADDCLUSTER place2')
.then(function (cluster) {
console.log(cluster);
});
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 } ]
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 } ]
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 } ]
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 } ]
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 } ]
从集群中选择(place
):
db.class.create('Place', 'V')
.then(function (Class) {
console.log("Created class "+Class.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
db.query('ALTER CLASS Place ADDCLUSTER place2')
.then(function (cluster) {
console.log(cluster);
});
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 } ]
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 } ]
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 } ]
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 } ]
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 } ]
输出:
db.class.create('Place', 'V')
.then(function (Class) {
console.log("Created class "+Class.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
db.query('ALTER CLASS Place ADDCLUSTER place2')
.then(function (cluster) {
console.log(cluster);
});
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 } ]
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 } ]
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 } ]
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 } ]
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 } ]
从集群中选择(place2
):
db.class.create('Place', 'V')
.then(function (Class) {
console.log("Created class "+Class.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
db.query('ALTER CLASS Place ADDCLUSTER place2')
.then(function (cluster) {
console.log(cluster);
});
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 } ]
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 } ]
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 } ]
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 } ]
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 } ]
输出:
db.class.create('Place', 'V')
.then(function (Class) {
console.log("Created class "+Class.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
db.query('ALTER CLASS Place ADDCLUSTER place2')
.then(function (cluster) {
console.log(cluster);
});
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 } ]
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 } ]
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 } ]
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 } ]
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 } ]
从类的所有簇中选择Place
:
db.class.create('Place', 'V')
.then(function (Class) {
console.log("Created class "+Class.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
db.query('ALTER CLASS Place ADDCLUSTER place2')
.then(function (cluster) {
console.log(cluster);
});
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 } ]
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 } ]
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 } ]
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 } ]
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 } ]
输出:
db.class.create('Place', 'V')
.then(function (Class) {
console.log("Created class "+Class.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
db.query('ALTER CLASS Place ADDCLUSTER place2')
.then(function (cluster) {
console.log(cluster);
});
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 } ]
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 } ]
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 } ]
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 } ]
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 } ]
正如您所看到的,顶点在同一个类中,但在不同的簇中
希望它能帮助詹姆斯·罗特(James Root,tks)纠正拼写错误的“难题”!你可以使用sql。从orientjs你可以使用db.query API我明白你的意思。但我关心的是如何在orientjs中使用“集群”进行编码。嗨@Sunrise,你有机会尝试我的解决方案吗?非常感谢你提供的详细示例。我肯定会在接下来的几天尝试你的解决方案,并在这里发表评论。嗨@Sunrise,很高兴能提供帮助。嗨@Sunrise,我忘了一件事:我在类Place
中只创建了一个新集群place2
,因为默认情况下,会创建一个类名小写的集群(在本例中为Place
)。您好@Sunrise,您在OrientJS中尝试过cluster
功能吗?