Database

[{"_id":0,"friends":[[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],[0,1,2]]}]

Query

db.collection.aggregate([{$project:{commonFriendIds:{$reduce:{input:"$friends",initialValue:{$arrayElemAt:["$friends",0]},in:{$setIntersection:["$$this","$$value"]}}}}}])

Result