Skip to content

Instantly share code, notes, and snippets.

@cristopher-rodrigues
Last active December 16, 2015 23:39
Show Gist options
  • Save cristopher-rodrigues/ddb2a001db19b76e330e to your computer and use it in GitHub Desktop.
Save cristopher-rodrigues/ddb2a001db19b76e330e to your computer and use it in GitHub Desktop.
mongo aggregate
db.collection
.aggregate(
[
{$match:{$text:{$search: "STRING"}, {/*wEVER*/}}},
{$lookup:{from: 'otherCollectionJoin', localField: 'p', foreignField: '_id', as: 'otherCollectionJoin'}},
{$unwind:"otherCollectionJoin"},
{
$group:{
"_id":"$_id"
, type: {$addToSet: "otherField"}
}
},
{$match:{
/*Other Match?*/
}},
{$unwind:"OtherField"},
{$limit: (limit+skip)},
{$skip: skip}
]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment