Mongo Join
Example
db.facility.aggregate([ { $lookup: { from: "facilities", localField: "created_by", foreignField: "id", as: "maker" } } ])
Findone
[ { $lookup: { from: "users", localField: "edited_by", foreignField: "id", as: "editor" } }, { "$project": { "editor": { "$arrayElemAt": [ "$editor", 0 ] } }} ]
Also findone
How to use MongoDBs aggregate `$lookup` as `findOne()`
So as you all know, find() returns an array of results, with findOne() returning just a simply object. With Angular, this makes a huge difference. Instead of going {{myresult[0].name}}, I can simply
https://stackoverflow.com/questions/37691727/how-to-use-mongodbs-aggregate-lookup-as-findone
$lookup (aggregation) - MongoDB Manual
Performs a left outer join to an unsharded collection in the same database to filter in documents from the "joined" collection for processing. To each input document, the stage adds a new array field whose elements are the matching documents from the "joined" collection. The stage passes these reshaped documents to the next stage.
https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/

