In releases prior to 2.6 the following statement would work
"read": { "$sum": { "$eq": [ "$read", true ] } }
|
Where essentially the "$eq" operation evaluated to true or false and was included in the $sum as either 1 or 0.
neillunn: I can't reproduce this behavior in 2.2 or 2.4. See the following shell session from 2.4.10:
> db.foo.insert({read:true})
|
WriteResult({ "nInserted" : 1 })
|
> db.foo.find()
|
{ "_id" : ObjectId("534ad9fae209ec7c576b7e67"), "read" : true }
|
> db.foo.aggregate({$group:{_id:"x",read:{$sum:{$eq:["$read",true]}}}})
|
{ "_id" : "x", "read" : 0 } // Are you expecting "read" to have a value of 1 here?
|
Unless I'm missing something, the $sum operator has always added treated boolean values as zero with respect to sum calculation. Could you specify which pre-2.6 version you were using, and give an end-to-end example which exhibits the "working" behavior you're describing with that version?
|