Met de nieuwste Mongo 3.4 versie kun je gebruik maken van $graphLookup om de relatie te identificeren.
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]
}
}
}])