Med den seneste Mongo 3.4 version kan du gøre brug af $graphLookup at identificere forholdet.
db.Friends.aggregate([{
$match: {
user: 'Jim'
}
}, {
$graphLookup: {
from: 'Friends',
startWith: '$user2',
connectFromField: 'user2',
connectToField: 'user',
maxDepth: 0,
as: 'relationship'
}
}, {
$project: {
_id: 0,
user: '$user2',
friends_with_me: {
$cond: [{
$eq: [{
$size: "$relationship"
}, 0]
}, false, true]
}
}
}])