mongodb/node-mongodb-native — pull request #608 by rrusso2007 (2012-05-15 21:46:17+00:00)
Title: Fixed bug where collection.group keyf given as Code is processed as a regular object

Although the reduce and finalize functions accept BSON.Code for the function, the keyf function did not. What was missing was a simple check at the beginning where if it isn't a function and is an object then you call Object.keys(keyf) which makes the new keyset into ['_bsontype','code','scope'] which are the instance variables of the Code object. I added the simple instanceof check in that line and then added the same instanceof check where you check if typeof(keyf) === 'function' which inside of that if statement you already have the valid code for handling either Code or function input.

I added an extra step to the test_map_reduce which takes you're already existing test for passing a keyf function and I copied it verbatim except that I wrapped the function in new Code(). The test fails without the changes and passes with them and now I can make functions from strings for keyf.

The final change I made is that I couldn't get ANY tests to pass on the basic npm test. After investigation I saw in your Makefile that you run:

test_pure: build_native
@echo "\n == Run All tests minus replicaset tests=="
$(NODE) dev/tools/test_all.js --noreplicaset --boot --noactive

however in test_all.js I noticed --noactive is not an option and that it should be --nonative. When I made this final change all tests passed and keyf works with Code.