Skip to content

Instantly share code, notes, and snippets.

@mizvol
Created April 21, 2017 10:03
Show Gist options
  • Save mizvol/485c5e12e4e45af716123a2375edbbaf to your computer and use it in GitHub Desktop.
Save mizvol/485c5e12e4e45af716123a2375edbbaf to your computer and use it in GitHub Desktop.
db.allPosts.aggregate([
{$group: {_id: "$user.id", tags: {$addToSet: "$tags"}}},
{$unwind: "$tags"},
{$unwind: "$tags"},
{$group: {_id: "$_id", tags: {$addToSet: "$tags"}}},
{$out: "tags"}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment