Skip to content

Instantly share code, notes, and snippets.

@luandevpro
Created October 17, 2019 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luandevpro/059e6045a22768b5c2988f6aa10ae083 to your computer and use it in GitHub Desktop.
Save luandevpro/059e6045a22768b5c2988f6aa10ae083 to your computer and use it in GitHub Desktop.
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