compile mongo queries into javascript functions