MongoDB Documentation, Release 3.0.4 reduceFunction2('myKey', myTestObjects); { "count" : 6, "qty" : 30 } The reduce function takes a key and a values array as its argument. You can test that the result of the reduce function does not depend on the order of the elements in the values array. { "count" : 6, "qty" : 30 } reduceFunction2('myKey', values1); reduceFunction2('myKey', values2); 4. Verify the reduceFunction2 returned the same result: 3. Invoke the reduceFunction2 first with values1 and then with values2 : 467 7.3. Aggregation Examples var reduceFunction2 = function (keySKU, valuesCountObjects) { reducedValue = { count: 0, qty: 0 }; for ( var idx = 0; idx < valuesCountObjects.length; idx++) { reducedValue.count += valuesCountObjects[idx].count; reducedValue.qty += valuesCountObjects[idx].qty; } return reducedValue; }; var values1 = [ { count: 1, qty: 5 }, { count: 2, qty: 10 }, { count: 3, qty: 15 } ]; var values2 = [ { count: 3, qty: 15 }, { count: 1, qty: 5 }, { count: 2, qty: 10 } ]; var myTestObjects = [ { count: 1, qty: 5 }, { count: 2, qty: 10 }, { count: 3, qty: 15 } ]; 6. Define a sample array of documents: 7. Invoke the reduceFunction2 with myTestObjects : 8. Verify the reduceFunction2 returned a document with exactly the count and the qty field: 1. Define a sample values1 array and a sample values2 array that only differ in the order of the array elements: 2. Define a reduceFunction2 function that takes the arguments keySKU and valuesCountObjects . valuesCountObjects is an array of documents that contain two fields count and qty : Ensure Insensitivity to the Order of Mapped Values