Created
December 2, 2012 11:30
-
-
Save yojimbo87/4188295 to your computer and use it in GitHub Desktop.
Arango queries test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get all event titles with companies count based on user hash | |
LET uid = ( | |
FOR u IN Users | |
FILTER u.Hash == "jb" | |
RETURN u._id | |
) | |
FOR e IN Events | |
FILTER e.OwnerID == uid[0] | |
RETURN { "Event": e.Title, "Companies": LENGTH(e.Companies) } | |
// get all events with company titles, exhbitor and kiosk counts | |
FOR e IN Events | |
/*FILTER e._id == "2811057/12772529"*/ | |
LET companies = ( | |
FOR c IN Companies | |
FILTER c._id IN e.Companies | |
RETURN { "Title": c.Title, "eCount": LENGTH(c.Exhibitors), "kCount": LENGTH(c.Kiosks) } | |
) | |
RETURN { "Event": e.Title, "Companies": companies[*].Title, "Companies count": LENGTH(companies), "Exhibitors count": SUM(companies[*].eCount), "Kiosks count": SUM(companies[*].kCount) } | |
// get specific event company (by event ID and exhibitor ID) with exhibitors and kiosks | |
FOR e IN Events | |
FILTER e._id == "2811057/12772529" | |
FOR ec IN e.Companies | |
FOR c IN Companies | |
FILTER c._id == ec && "10151089/11789489" IN c.Exhibitors | |
LET exhibitors = ( | |
FOR ce in c.Exhibitors | |
FOR u in Users | |
FILTER u._id == ce | |
RETURN { "_id": u._id, "Name": CONCAT(u.FirstName, " ", u.LastName) } | |
) | |
LET kiosks = ( | |
FOR ck in c.Kiosks | |
FOR k in Kiosks | |
FILTER k._id == ck | |
RETURN { "_id": k._id, "Title": k.Title } | |
) | |
RETURN { "Company": c.Title, "Exhibitors": exhibitors, "Kiosks": kiosks } | |
// same query with use of DOCUMENT function | |
FOR e IN Events | |
FILTER e._id == "6911114/13792394" | |
FOR c IN DOCUMENT(Companies, e.Companies) | |
FILTER "10843274/12481674" IN c.Exhibitors | |
LET exhibitors = ( | |
FOR u in DOCUMENT(Users, c.Exhibitors) | |
RETURN { "_id": u._id, "Name": CONCAT(u.FirstName, " ", u.LastName) } | |
) | |
LET kiosks = ( | |
FOR k in DOCUMENT(Kiosks, c.Kiosks) | |
RETURN { "_id": k._id, "Title": k.Title } | |
) | |
RETURN { "Company": c.Title, "Exhibitors": exhibitors, "Kiosks": kiosks } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment