【问题标题】:ArangoDB - Collection not found error though the collection is createdArangoDB - 虽然创建了集合但未找到集合错误
【发布时间】:2016-12-28 11:21:06
【问题描述】:

我正在两个文档之间创建一条边“has_taken”,如下所示:

sin_graph.createEdge("has_taken", userDoc._id, tripDoc._id, edgeAttributes={})

我收到以下错误:

File "/Library/Python/2.7/site-packages/pyArango/graph.py", line 135, in createEdge raise CreationError("Unable to create edge, %s" % r.json()["errorMessage"], data) CreationError: Unable to create edge, collection not found. Errors: {u'code': 404, u'errorNum': 1203, u'errorMessage': u'collection not found', u'error': True}

名称为“has_taken”的集合存在,但出现上述错误。

【问题讨论】:

  • 你能写更多细节吗?你从哪里得到sin_graph
  • 我通过以下命令得到了我的图表 sin_graph = db.graphs['Graph_name'] 我使用 arangoDB 的 GUI 创建了这个图表
  • 您确定您使用的是正确的数据库吗?而不是 _system>
  • 是的,我使用了正确的数据库。我想我弄错了,我读过一个图可以包含类似类型的边。在我的图表中,我进入了一个与配置不同的边缘。

标签: python arangodb pyarango


【解决方案1】:

我认为这可能是因为您创建了 Collection 类型而不是 Edge 类型的集合(哈哈,我知道,令人困惑。)

但是在制作集合时叫做“has_taken”,而不是

db.createCollection(className="Collection", name="has_taken")

试试

db.createCollection(className="Edges", name="has_taken")

我在阅读this 页面时注意到了这一点。 (单击该链接时,请查看屏幕的最顶部。功能及其说明就在上面,并提到了这种差异。)

createCollection(className='Collection', waitForSync=False, **colArgs)[source]

创建一个集合并返回它。 ClassName 继承自 Collection 或 Egdes 的类的名称,也可以将其设置为“Collection”或“Edges”,以创建文档或边缘的无类型集合。

【讨论】:

    【解决方案2】:

    我已将 social graph example 示例转换为 pyArango;它说明了使用它维护图形数据时要做的事情的顺序:

    #!/usr/bin/python
    import sys
    from pyArango.connection import *
    from pyArango.graph import *
    from pyArango.collection import *
    
    
    class Social(object):
            class male(Collection) :
                _fields = {
                    "name" : Field()
                }
    
            class female(Collection) :
                _fields = {
                    "name" : Field()
                }
    
            class relation(Edges) :
                _fields = {
                    "number" : Field()
                }
    
            class social(Graph) :
    
                _edgeDefinitions = (EdgeDefinition ('relation',
                                                    fromCollections = ["female", "male"],
                                                    toCollections = ["female", "male"]),)
                _orphanedCollections = []
    
    
            def __init__(self):
                   self.conn = Connection(username="root", password="")
    
                   self.db = self.conn["_system"]
                   if self.db.hasGraph('social'):
                       raise Exception("The social graph was already provisioned! remove it first")
    
                   self.female   = self.db.createCollection("female")
                   self.male     = self.db.createCollection("male")
    
                   self.relation = self.db.createCollection("relation")
    
                   g = self.db.createGraph("social")
    
                   a = g.createVertex('female', {"name": 'Alice',  "_key": 'alice'});
                   b = g.createVertex('male',  {"name": 'Bob',    "_key": 'bob'});
                   c = g.createVertex('male',   {"name": 'Charly', "_key": 'charly'});
                   d = g.createVertex('female', {"name": 'Diana',  "_key": 'diana'});
                   a.save()
                   b.save()
                   c.save()
                   d.save()
    
                   g.link('relation', a, b, {"type": 'married', "_key": 'aliceAndBob'})
                   g.link('relation', a, c, {"type": 'friend', "_key": 'aliceAndCharly'})
                   g.link('relation', c, d, {"type": 'married', "_key": 'charlyAndDiana'})
                   g.link('relation', b, d, {"type": 'friend', "_key": 'bobAndDiana'})
    
    
    Social()
    

    【讨论】:

      猜你喜欢
      • 2020-08-01
      • 1970-01-01
      • 2020-05-27
      • 2013-08-08
      • 1970-01-01
      • 1970-01-01
      • 2020-03-23
      • 2016-01-30
      • 1970-01-01
      相关资源
      最近更新 更多