MongoDB v2.4.9 sort by boolean field
The code above works, my data was bad. As I wrote in the comment above, some of the documents had isFoo as a String (not Boolean) and that's why I was seeing the mixed results.
I had to change the type of the field from String to Boolean so I tried this:
db.users.find( { 'isFoo' : { $exists : true } } ).forEach( function (x) { x.isFoo = new Boolean(x.isFoo); db.users.save(x); });
But that just turned all of the isFoo fields to Objects.
Seeing as I was really tired of dealing with this issue I just used the following to set all the isFoo fields to false and just handle the changes manually.
db.users.find( { 'isFoo' : { $exists : true } } ).forEach( function (x) { x.isFoo = false; db.users.save(x); });
This was very annoying.