1.

How would you troubleshoot locking issues in MongoDB?

Answer»

The $GRAPHLOOKUP LOOKS like this for a query from the EMPLOYEES collection where “manager” is the self-referencing field

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

The value of as, which is “Reporting Structure” in this case is the name of the array field which contains the documents traversed in the $graphLookup to reach the output document.   

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 " }

“Reporting Structure” for each output document would look like this

{ "_id" : 5, "name" : "John" , "manager" : "David", "Reporting Structure" : [] } { "_id" : 6, "name" : "Richard", "manager" : " John ",   "Reporting Structure" : [{ "_id" : 5, "name" : "John" , "manager" : "David" }] } { "_id" : 7, "name" : "Stacy"    , "manager" : " Richard", "Reporting Structure" : [{ "_id" : 5, "name" : "John", "manager" : "David" }       { "_id" : 6, "name" : "Richard", "manager" : " John " }]  }


Discussion

No Comment Found