Starting with collection:
[
{ _id: 0, name: ‘steevej’ },
{ _id: 2, name: ‘steevej’ },
{ _id: 3, name: ‘steevej’ }
]
and using the following:
pipeline = [
{ { $match : { _id:0 } } ,
{
'$graphLookup': {
from: 'graph_lookup',
startWith: '$name',
connectFromField: 'name',
connectToField: 'name',
as: 'lookup_result',
maxDepth: 0,
restrictSearchWithMatch: { '$expr': { '$ne': [ '$_id', 0 ] } }
}
}
]
I got
[
{
_id: 0,
name: 'steevej',
lookup_result: [ { _id: 3, name: 'steevej' }, { _id: 2, name: 'steevej' } ]
}
]
On a free Atlas tier. I got more that expected, you only want lookup_result.0. May be there is a way to limit the size to 1 with restrictSearchWithMatch.