We need it for the following use case:
var myPerceptualHash = '0239582305980';
db.coll1.find().sort({
$by : function( a, b ) {
var md = require('hamming-distance');
return hm(myPerceptualHash, a.phash) < hm(myPerceptualHash, b.phash);
}
}).limit(1)
This is even more special than just defining a sorting function that relates a with b, as It will require to use an "external" parameter to contrast to at the moment of the sorting.