A $graphLookup stage in a pipeline will have the following form:
Here’s the meaning of each field:
- from: Equivalent to the from field in $lookup, this specifies the collection that this stage retrieves results from.
- startWith: Specifies the connectToField value(s) that we should start our recursive search with. For example, this could be a list of Twitter handles.
- connectFromField: Specifies a field in each document in the from collection that is used to perform the next recursive query. For example, this could be a list of Twitter handles of users that have followed the New York Times.
- connectToField: Specifies a field in each document in the from collection that is queried against with each recursive query. For example, this could be a user’s Twitter handle.
- as: Specifies a field in the output document that will be filled with the array of results of the $graphLookup.
- maxDepth: (optional) Specifies a maximum recursive depth for the $graphLookup.
- depthField: (optional) Specifies a field in each result document that will be set to the recursive depth at which the document was retrieved. For example, this value might represent the number of flights you need to take to get from New York to Beijing.
Given a starting person, compute their friend network.
Contents of from Collection, contacts: