GithubHelp home page GithubHelp logo

mikebeaulieuqtech / graph-who Goto Github PK

View Code? Open in Web Editor NEW

This project forked from plusn-nuri/graph-who

0.0 1.0 0.0 185 KB

A MongoDB graph exploreation

License: The Unlicense

JavaScript 100.00%

graph-who's Introduction

mongodb-graph-who

A graph exploration.

Seeding the database

Data for the exploration can be found in the data directory. The data is stored in JSON format, and can be imported using mongoimport

mongoimport --db "graph-who" --collection adversary adversary.json --drop
mongoimport --db "graph-who" --collection companion companion.json --drop
mongoimport --db "graph-who" --collection cypher cypher.json --drop
mongoimport --db "graph-who" --collection arcs arcs.json --drop
mongoimport --db "graph-who" --collection nodes nodes.json --drop
mongoimport --db "graph-who" --collection people people.json --drop

Syntax Basics

Query one doc using the Aggregation Framework

    db.nodes.aggregate([{$match:{name:"dr"}}])
    db.arcs.aggregate([{$match:{_id:"dr"}}])
    db.arcs.aggregate([{$match:{_id:"amy"}}])
    db.arcs.aggregate([{$match:{arc:"amy"}}])

Adding a graph pipeline stage

    // Relate the current pipeline node to a constant (value of 'from' is fixed)
    db.nodes.aggregate([
        {$match:{name:"dr"}},
        {$graphLookup:{
            from: 'arcs',
            startWith: 'dr',
            connectFromField: 'arc',
            connectToField: '_id',
            as: 'arcs',
            maxDepth: 0
            }
        }
    ]).pretty()

    // Relate the current pipeline node to connected graph arcs (value of 'from' is dynamic)
    db.nodes.aggregate([
        {$match:{name:"dr"}},
        {$graphLookup:{
            from: 'arcs',
            startWith: '$name',
            connectFromField: 'arc',
            connectToField: '_id',
            as: 'arcs',
            maxDepth: 0
            }
        }
    ]).pretty()

    // Descend further in the graph by increasing the maxDepth field
    db.nodes.aggregate([
        {$match:{name:"dr"}},
        {$graphLookup:{
            from: 'arcs',
            startWith: 'dr',
            connectFromField: 'arc',
            connectToField: '_id',
            as: 'arcs',
            maxDepth: 2
            }
        }
    ]).pretty()

    // Add an output field named 'howDeep' containing the depth of the connected graph node
    db.nodes.aggregate([
        {$match:{name:"dr"}},
        {$graphLookup:{
            from: 'arcs',
            startWith: 'dr',
            connectFromField: 'arc',
            connectToField: '_id',
            as: 'arcs',
            maxDepth: 2,
            depthField: 'howDeep'
            }
        }
    ]).pretty()

Data sources used for creating this exploration include:

  1. https://docs.google.com/spreadsheets/d/1-wpscGBquVJnI5i9lIygBQWW-OrP_ypDng4ZuQvwLeU/edit#gid=0
  2. Wikipedia
  3. Fan pages
  4. Dr. Who TV series pages
  5. Arbitrary data for demo purposes

graph-who's People

Contributors

nurih avatar plusn-nuri avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.