1.

How does MongoDB WiredTiger storage engine ensure data durability?

Answer»

Recursive queries can be performed within a collection using $graphLookUp which is an aggregate pipeline stage.

If a collection has a self-referencing field like the classic example of MANAGER for an employee, then a QUERY to get the entire REPORTING structure for manager “David” would look like this

db.employees.aggregate( [    {       $graphLookup: {          from: "employees",          startWith: "David",          connectFromField: "manager",          connectToField: "name",          as: "Reporting Structure"       }    } ] )

For the following documents in the employee collection,

{ "_id" : 4, "name" : " David "  , "manager" : "Sarah" } { "_id" : 5, "name" : "John"      , "manager" : "David" } { "_id" : 6, "name" : "Richard", "manager" : " John " } { "_id" : 7, "name" : "Stacy"    , "manager" : " Richard " }

Output of the above $graphLookup operation would result in the following 3 documents returned

{ "_id" : 5, "name" : "John"      , "manager" : "David", … } { "_id" : 6, "name" : "Richard", "manager" : " John ",  … } { "_id" : 7, "name" : "Stacy"    , "manager" : " Richard", … }

The hierarchy starts with “David” which is specified in startWith and there on the DATA for each of the members in that reporting hierarchy are fetched recursively 



Discussion

No Comment Found