Bit of a pain that. maybe mapReduce?
db.collection.mapReduce(
function() {
emit( this._id, values: {
email: this.user_data.email.toLowerCase(),
other: this.other_field.toLowerCase()
});
},
function(){},
{
"out": { "replace": "newCollection" }
}
)
And the get the results from the new collection with .find()
.
Or you could wait for 2.6, where aggregate does return a cursor
db.collection.aggregate([
{ "$project": { "email": { "$toLower": "$user_data.email" } } }
])
Really not sure of your use case. E-mail should be considered case insensitive, so any matching should take that into consideration.
But if comparison is your thing, why not use strcasecomp ?
At the end of the day, this is probably something that you should update in your data, and then make sure that new records are always inserted with the email address in lowercase.