Created
August 3, 2018 21:17
-
-
Save npentrel/d8c5a99c0e1734ecb08079d229425b9f to your computer and use it in GitHub Desktop.
Use aggregation expressions in queries with $expr - find operation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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