简体   繁体   中英

ArangoDB - Collection not found error though the collection is created

I am creating an edge "has_taken" between two documents as follows:

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

And I am getting the following error:

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}

The collection with the name "has_taken" is present and yet I am getting the above error.

I have transpiled the social graph example example to pyArango; It ilustrates the sequence of things to do when maintaining graph data with it:

#!/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()

I think it may be because you made a collection of type Collection and not of type Edge (haha, confusing, I know.)

But when making the collection called "has_taken", instead of

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

try

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

I noticed that when I was reading this page. (Look at the very top of your screen when you click that link. The function and its description is right up there and it mentions this difference.)

 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM