Пример #1
0
    def list_collection_names(self, filter=None, session=None):
        """filter: only name field type with eq,ne or regex operator

        session: not supported
        for supported operator please see _LIST_COLLECTION_FILTER_ALLOWED_OPERATORS
        """
        field_name = 'name'

        if session:
            raise NotImplementedError('Mongomock does not handle sessions yet')

        if filter:
            if not filter.get('name'):
                raise NotImplementedError('list collection {0} might be valid but is not '
                                          'implemented yet in mongomock'.format(filter))

            filter = {field_name: {'$eq': filter.get(field_name)}} \
                if isinstance(filter.get(field_name), str) else filter

            _verify_list_collection_supported_op(filter.get(field_name).keys())

            return [name for name in list(self._store._collections)
                    if filter_applies(filter, {field_name: name}) and
                    not name.startswith('system.')]

        return [
            name for name in self._get_created_collections()
            if not name.startswith('system.')
        ]
Пример #2
0
 def _find_matches_for_depth(query):
     if isinstance(query, list):
         query = {'$in': query}
     matches = foreign_collection.find({connect_to_field: query})
     new_matches = []
     for new_match in matches:
         if filtering.filter_applies(restrict_search_with_match, new_match) \
                 and new_match['_id'] not in found_items:
             if depth_field is not None:
                 new_match = collections.OrderedDict(new_match, **{depth_field: depth})
             new_matches.append(new_match)
             found_items.add(new_match['_id'])
     return new_matches
Пример #3
0
 '$graphLookup':
 None,
 '$group':
 _handle_group_stage,
 '$indexStats':
 None,
 '$limit':
 lambda c, d, o: c[:o],
 '$listLocalSessions':
 None,
 '$listSessions':
 None,
 '$lookup':
 _handle_lookup_stage,
 '$match':
 lambda c, d, o: [doc for doc in c if filtering.filter_applies(o, doc)],
 '$out':
 _handle_out_stage,
 '$project':
 _handle_project_stage,
 '$redact':
 None,
 '$replaceRoot':
 None,
 '$sample':
 _handle_sample_stage,
 '$skip':
 lambda c, d, o: c[o:],
 '$sort':
 _handle_sort_stage,
 '$sortByCount':