Last active
October 29, 2015 00:31
-
-
Save harishvc/2ae4de25bfa75e5bd680 to your computer and use it in GitHub Desktop.
MongoDB & Neo4j Query
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
#MongoDB | |
pipeline = [ | |
{ '$match': {'type':'WatchEvent'}}, | |
{ '$group': {'_id': {'full_name': '$full_name'}, 'stars': { '$sum' : 1 }}}, | |
{ '$project': { '_id': 0, 'full_name': '$_id.full_name', 'stars': '$stars' } }, | |
{ '$sort' : { 'stars': -1 }}, | |
{ '$limit': 10} | |
] | |
mycursor = db.aggregate(pipeline) | |
#Neo4j Cypher | |
for record in graph.cypher.execute("match (a:Repository)-[r]->(b:Organization) return count(r) as count"): | |
print(record.count) | |
#Cypher - Simple recommendation for repository edx-platform | |
MATCH (a {id:"edx/edx-platform"})-[r1:IS_ACTOR|IN_ORGANIZATION]->(match)<-[r2:IS_ACTOR|IN_ORGANIZATION]-(b) | |
with b, collect (distinct match.id) as connections, collect (distinct type(r1)) as rel1 | |
where length(connections) >= 1 return b.id, length(connections) as count, length(rel1) as rel | |
order by length(connections) desc limit 5 | |
#Sample output | |
b.id count rel | |
amir-qayyum-arbisoft/edx-platform 25 1 | |
raccoongang/edx-platform 21 1 | |
Shrhawk/edx-platform 17 1 | |
mitocw/edx-platform 13 1 | |
edx-solutions/edx-platform 13 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment