pyarango - KeyError: "There's no child of Graph by the name of: collection name" -


while creating graph, seeing error. how define child of collection or graph?

i had same problem you, trying figure out, day long ):<

turns out, here's how things work.

let's assume connected , everything:

conn = connection(arangourl="http://arangodb:8529", username="root", password="secret") db = conn.createdatabase(name="mydb3") 

turns out, graphs wayyy different collections, , though can make collections of type collection db.createcollection(classname="collection", name="users") , collections of type edges, db.createcollection(classname="edges", name="follows") easily, can't make graphs db.creategraph(name="social", createcollections=false) right off bat, way can collections. according code pyarango developer wrote (and reaaalllyy sparse hard understand documentation) have first kind of explain structure of specific graph before can make new graph. , you're supposed making bunch of classes extend other classes wrote. wrote (vaguely, lol) in his documentation ):

the creator of pyarango wants structure of specific edges , vertices using in graph, declared fancy logging, before make graph. there 2 ways create collection. in docs, says

createcollection(classname='collection', waitforsync=false, **colargs) 

creates collection , returns it. classname name of class inheriting collection or egdes, can set ‘collection’ or ‘edges’ in order create untyped collections of documents or edges.

what means intends make collections not this: db.createcollection(classname="edges", name="follows") but creating new class first, class extends either collection or edges, , have fancy definitions, in class. basically, when create in special way i'm show you, keeps log of these special, non-default collections, in metaclass. in order graph work, can't use little default shortcut, have make classes because graph thing check existence inside metaclass. after make new classes extend edges , collection, can leave them empty now. usually, if developer wants document in class definition not database few fields or other things these collections have, he'll put them in these class extensions.

class follows(edges) :     pass  class users(collection) :     pass 

create actual collections, after make these classes! might tempted db.createcollection(classname="collection", name="users") before make these classes, don't. make pyarango confused. also, instead of writing default way, db.createcollection(classname="collection", name="users") now, create vew vertices testing, this:

db.createcollection(classname="users") doc = db["users"].createdocument() doc._key = "custom_key" doc["name"] = "tesla" doc["age"] = "28" doc.save() doc = db["users"].createdocument() doc._key = "custom_key2" doc["name"] = "porsche" doc.save() 

and few edges testing:

db.createcollection(classname="follows") doc = db["follows"].createedge() doc._key = "custom_key" doc["_from"] = "users/custom_key" doc["_to"] = "users/custom_key2" doc.save() 

and part describe structure of graph, done extending graph class, in specific way. once again, no clue _orphanedcollections i'll let know if find out. 'follows' in following code block has same word follows in class follows(edges) : , same word db.createcollection(classname="edges", name="follows"), basically, named edge collection other follows. make sure same name, in 3 locations. , same goes users - inside of class social(graph) , in place write class users(collection) , time db["users"].createdocument() - these places use same name. if decide have collection different name, maybe people or something, make sure consistent throughout code it. 3 spots correspond same name. not sure how.

class social(graph):     _edgedefinitions = (edgedefinition ('follows', fromcollections = ["users"], tocollections = ["users"]), )     _orphanedcollections = [] 

and now, finally, after trouble, able write following line:

g = db.creategraph(name="social", createcollections=false) 

make sure use same name write name="social" , wrote class social(graph) names correspond because creategraph literally calls class wrote. when you're writing name="social" you're passing entire class parameter creategraph. eek.

anyways, after trouble, should work now. if open arangodb web interface, log in, select mydb3, , click "graph" you'll see graph made. yay.

note: reason, if add new edges , vertices after creating graph, (like below) ones had before creating graph ... disappear. if figure out why, i'll edit answer. now, create them before or after.

a = g.createvertex('users', {"name": 'toyota',  "_key": 'custom_key6'}); b = g.createvertex('users',  {"name": 'honda',    "_key": 'custom_key7'}); g.link('follows', a, b, {"extra_info": 'testing1', "_key": 'custom_key8'}) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -