count - Optimal way of join with counting Arango -


i wanted write efficent query in arango query language working join counting.

in database have users, tags , usertag collections. users , tags connected 'edge' stored in usertag. want list tags (with data tags collection) , each tag - number of users connected tag.

what have (it works):

for tag in tags     let foronetag = (       v, e, p in 1 outbound tag       usertag         return {e}     )     return {tag: tag.tagname, numberofusers: length(foronetag)} 

i feel not efficient way regarding time , memory. there more 'arangoic' way of doing it?

your query good. 1 small optimisation: use return e instead of return {e}, don't have wrap e inside document because it's document.

for tag in tags   let foronetag = (     v, e, p in 1 outbound tag       usertag       return e     )   return {tag: tag.tagname, numberofusers: length(foronetag)} 

alternatively use following query. these query more performant returns tags has @ least 1 connected user.

for tag in tags   v, e, p in 1 outbound tag     usertag     return {tag: tag.tagname, numberofusers:length(p.edges)} 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -