Created
October 17, 2019 08:49
-
-
Save luandevpro/059e6045a22768b5c2988f6aa10ae083 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports = function(payload, response) { | |
const atlas = context.services.get('mongodb-atlas'); | |
return atlas | |
.db('apitutorial') | |
.collection('posts') | |
.aggregate([ | |
{ | |
$match: { | |
_id: BSON.ObjectId(payload.query.id), | |
}, | |
}, | |
{ | |
$project: { | |
title: 1, | |
desc: '$description', | |
userId: 1, | |
}, | |
}, | |
{ | |
$lookup: { | |
from: 'users', | |
let: { userId: '$userId' }, | |
pipeline: [ | |
{ | |
$project: { name: 1, age: 1 }, | |
}, | |
], | |
as: 'userId', | |
}, | |
}, | |
]) | |
.toArray(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment