我可以在gremlin查询中限定orientdb顶点/边类吗?

时间:2016-04-13 20:08:27

标签: orientdb gremlin

orientdb有一个看似非标准的'功能,可以创建特定的顶点和边类。

g.createVertex('class:person')

但我不清楚我是否/如何通过'标准'来获得该课程的资格? GREMLIN?

我看过像这样的语法的引用:

g.V('@class','person')...

here,但后来提到了这种语法边缘指数。

任何人都可以阐明这个话题吗?

1 个答案:

答案 0 :(得分:3)

似乎Gremlin没有采用Schema功能,并且并非所有图形数据库都支持模式,所以我不认为您可以直接使用Gremlin操作OrientDB Schema。

无论如何,您可以使用createVertexType()命令在OrientDB trhought Gremlin中创建类。

  1. 与ODB数据库的连接:

    g = new OrientGraphNoTx('remote:localhost/GremlinDB')
    
    ==>orientgraphnotx[remote:localhost/GremlinDB]
    
  2. 创建扩展Person的顶点类V

    g.createVertexType('Person','V')
    
    ==>Person
    
  3. 现在,如果您查看OrientDB Studio中的Schema,您将看到创建的新类:

    enter image description here

    <强> EDITED

    添加了两个顶点后

    enter image description here

    我们可以找到name = 'John'的人。

    1. 使用has()

      g.V.has('@class','Person').has('name','John')
      
      ==>v(Person)[#12:0]
      
    2. 使用has() + T运营商:

      g.V.has('@class','Person').has('name',T.eq,'John')
      
      ==>v(Person)[#12:0]
      
    3. 使用contains()

      g.V.has('@class','Person').filter{it.name.contains('John')}
      
      ==>v(Person)[#12:0]
      
    4. 使用==

      g.V.has('@class','Person').filter{it.name == 'John'}
      
      ==>v(Person)[#12:0]
      
    5. 希望有所帮助