Skip to content

Instantly share code, notes, and snippets.

@npentrel
Created August 3, 2018 21:17
Show Gist options
  • Save npentrel/d8c5a99c0e1734ecb08079d229425b9f to your computer and use it in GitHub Desktop.
Save npentrel/d8c5a99c0e1734ecb08079d229425b9f to your computer and use it in GitHub Desktop.
Use aggregation expressions in queries with $expr - find operation
> db.accounts.find({
     $expr : {
         $gt : [
             { $sum : ["$expenses"] },
             "$credits"
         ]
     }
 })
{ "_id" : 2, "credits" : 4000, "expenses" : [ 1000, 4000, 2000 ] }
{ "_id" : 4, "credits" : 2000, "expenses" : [ 2500, 750 ] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment