def to_mongo(self, disjunction=True):
q = {}<EOL>clauses = [e.expr for e in self._main]<EOL>if clauses:<EOL><INDENT>if disjunction:<EOL><INDENT>if len(clauses) + len(self._where) > <NUM_LIT:1>:<EOL><INDENT>q['<STR_LIT>'] = clauses<EOL><DEDENT>else:<EOL><INDENT>q.update(clauses[<NUM_LIT:0>])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for c in clauses:<EOL><INDENT>q.update(c)<EOL><DEDENT><DEDENT><DEDENT>for c in (e.expr for e in self._main2):<EOL><INDENT>for field in c:<EOL><INDENT>if field in q:<EOL><INDENT>q[field].update(c[field])<EOL><DEDENT>else:<EOL><INDENT>q.update(c)<EOL><DEDENT><DEDENT><DEDENT>if self._where:<EOL><INDENT>wsep = '<STR_LIT>' if self._where[<NUM_LIT:0>].is_reversed else '<STR_LIT>'<EOL>where_clause = wsep.join([w.expr for w in self._where])<EOL>if disjunction:<EOL><INDENT>if not '<STR_LIT>' in q:<EOL><INDENT>q['<STR_LIT>'] = []<EOL><DEDENT>q['<STR_LIT>'].append({'<STR_LIT>': where_clause})<EOL><DEDENT>else:<EOL><INDENT>q['<STR_LIT>'] = where_clause<EOL><DEDENT><DEDENT>return q<EOL>
Create from current state a valid MongoDB query expression.

        :return: MongoDB query expression
        :rtype: dict