Define find/findOne comparator function outside of loop