def group(self, id=None, **kwargs):
if type(id) == str:<EOL><INDENT>if not id.startswith('<STR_LIT:$>'):<EOL><INDENT>id = '<STR_LIT:$>' + id<EOL><DEDENT><DEDENT>query = {<EOL>'<STR_LIT>': id<EOL>}<EOL>for key in kwargs:<EOL><INDENT>query[key] = kwargs[key]<EOL><DEDENT>self._q.append({<EOL>'<STR_LIT>': query<EOL>})<EOL>return self<EOL>
Adds a group stage at aggregation query
:param id: The group id. Default value is None and group merge all documents
:param kwargs: The parameters-methods of group stage
:return: The current object