Python functions to convert SQL query to mongo query