def _create(self, constraint, exists_main):
c = constraint  <EOL>op = self._reverse_operator(c.op) if self._rev else c.op<EOL>mop = self._mongo_op_str(op)<EOL>loc = MongoClause.LOC_MAIN  <EOL>if op.is_exists():<EOL><INDENT>loc = MongoClause.LOC_MAIN2 if exists_main else MongoClause.LOC_MAIN<EOL>assert (isinstance(c.value, bool))<EOL>not_c_val = not c.value if self._rev else c.value<EOL>expr = {c.field.name: {mop: not_c_val}}<EOL><DEDENT>elif op.is_size():<EOL><INDENT>if op.is_variable():<EOL><INDENT>loc = MongoClause.LOC_WHERE<EOL>js_op = '<STR_LIT>' if self._rev else '<STR_LIT>'<EOL>expr = '<STR_LIT>'.format(c.field.name, js_op, c.value)<EOL><DEDENT>elif op.is_size_eq() and not self._rev:<EOL><INDENT>expr = {c.field.name: {'<STR_LIT>': c.value}}<EOL><DEDENT>else:<EOL><INDENT>self._check_size(op, c.value)<EOL>loc = MongoClause.LOC_WHERE<EOL>szop = ConstraintOperator(op.size_op)<EOL>if self._rev:<EOL><INDENT>szop.reverse()<EOL><DEDENT>js_op = self._js_op_str(szop)<EOL>expr = '<STR_LIT>'.format(c.field.name, js_op, c.value)<EOL><DEDENT><DEDENT>elif op.is_type():<EOL><INDENT>loc = MongoClause.LOC_WHERE<EOL>type_name = self.JS_TYPES.get(c.value, None)<EOL>if type_name is None:<EOL><INDENT>raise RuntimeError('<STR_LIT>'.format(c.value))<EOL><DEDENT>typeop = '<STR_LIT>' if self._rev else '<STR_LIT>'<EOL>expr = '<STR_LIT>'.format(c.field.name, typeop, type_name)<EOL><DEDENT>elif op.is_regex():<EOL><INDENT>expr = {c.field.name: {mop: c.value.pattern}}<EOL><DEDENT>else:<EOL><INDENT>if mop is None:<EOL><INDENT>expr = {c.field.name: c.value}<EOL><DEDENT>elif isinstance(c.value, bool):<EOL><INDENT>not_c_val = not c.value if self._rev else c.value<EOL>expr = {c.field.name: not_c_val}<EOL><DEDENT>else:<EOL><INDENT>expr = {c.field.name: {mop: c.value}}<EOL><DEDENT><DEDENT>return loc, expr<EOL>
Create MongoDB query clause for a constraint.

        :param constraint: The constraint
        :type constraint: Constraint
        :param exists_main: Put exists into main clause
        :type exists_main: bool
        :return: New clause
        :rtype: MongoClause
        :raise: ValueError if value doesn't make sense for operator