Skip to content

Instantly share code, notes, and snippets.

@jdjkelly
Last active May 30, 2017 01:38
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 jdjkelly/58a8bf4eb419ca1d8eafd0d4b4da451d to your computer and use it in GitHub Desktop.
Save jdjkelly/58a8bf4eb419ca1d8eafd0d4b4da451d to your computer and use it in GitHub Desktop.
// Given these documents in a collection
{ "_id" : ObjectId("512bc95fe835e68f199c8686"), "author" : "dave", "score" : 80 }
{ "_id" : ObjectId("512bc962e835e68f199c8687"), "author" : "dave", "score" : 85 }
{ "_id" : ObjectId("55f5a192d4bede9ac365b257"), "author" : "ahn", "score" : 60 }
{ "_id" : ObjectId("55f5a192d4bede9ac365b258"), "author" : "li", "score" : 55 }
{ "_id" : ObjectId("55f5a1d3d4bede9ac365b259"), "author" : "annT", "score" : 60 }
{ "_id" : ObjectId("55f5a1d3d4bede9ac365b25a"), "author" : "li", "score" : 94 }
{ "_id" : ObjectId("55f5a1d3d4bede9ac365b25b"), "author" : "ty", "score" : 95 }
// Apply this aggregation
db.articles.aggregate(
[ { $match : { author : "dave" } } ]
);
// Which returns these documents
{ "_id" : ObjectId("512bc95fe835e68f199c8686"), "author" : "dave", "score" : 80 }
{ "_id" : ObjectId("512bc962e835e68f199c8687"), "author" : "dave", "score" : 85 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment