Created
March 12, 2012 21:13
-
-
Save bpartridge83/2024712 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
http://www.mongodb.org/display/DOCS/Aggregation+Framework+-+Expression+Reference#AggregationFramework-ExpressionReference-Composition | |
$add:[5, $divide:[12, 2], 7] | |
With expressions, I can make it work properly with the nested operations enclosed in their own object: | |
$add:[5, { $divide:[12, 2] }, 7] | |
/* --------- Test --------- */ | |
> db.test.insert({ a: 5, b: 10, c: 20, d: 12 }); | |
> db.runCommand({ 'aggregate':'test', 'pipeline': [ { $project: { 'calculation': { $divide: [ $add: ['$a', '$b'], $add: ['$c', '$d'] ] } } } ] } ); | |
Mon Mar 12 14:12:16 SyntaxError: missing ] after element list (shell):1 | |
> db.runCommand({ 'aggregate':'test', 'pipeline': [ { $project: { 'calculation': { $divide: [ { $add: ['$a', '$b'] }, { $add: ['$c', '$d'] } ] } } } ] } ); | |
{ | |
"result" : [ | |
{ | |
"_id" : ObjectId("4f5e620fa40e4f69fffa10b4"), | |
"calculation" : 0.46875 | |
} | |
], | |
"ok" : 1 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment