ArangoDB集合未找到错误,尽管已创建集合

2024-04-20 09:22:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我在两个文档之间创建一个边缘,如下所示:

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\u take”的集合存在,但我得到了上面的错误。在


Tags: to文档id错误createnotcollectiongraph
2条回答

我想这可能是因为你收集了一个类型集合,而不是类型边缘(哈哈,我知道,令人困惑)

但是当你把这个系列叫做“has_nutake”时,而不是

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

试试看

^{pr2}$

我注意到当我读this页时。(点击该链接时,请查看屏幕顶部。函数和它的描述就在上面,它提到了这个区别。)

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

Creates a collection and returns it. ClassName the name of a class inheriting from Collection or Egdes, it can also be set to ‘Collection’ or ‘Edges’ in order to create untyped collections of documents or edges.

我已经将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()

相关问题 更多 >