Skip to content

Latest commit

 

History

History
33 lines (28 loc) · 669 Bytes

graph-lookup.md

File metadata and controls

33 lines (28 loc) · 669 Bytes

Demo for GraphLookup

Example of code

import {AggregateBuilder} from 'mongodb-aggregate-builder';

const aggBuilder = new AggregateBuilder();
aggBuilder.graphLookup({
    from: "employees",
    startWith: "$reportsTo",
    connectFromField: "reportsTo",
    connectToField: "name",
    as: "reportingHierarchy"
});
console.log(JSON.stringify(aggBuilder.build(), null, 2));

Result

[
    {
        "$graphLookup": {
            "from": "employees",
            "startWith": "$reportsTo",
            "connectFromField": "reportsTo",
            "connectToField": "name",
            "as": "reportingHierarchy"
        }
    }
]