mongoframes/frames.py
def one(cls, filter=None, **kwargs):
        """Return the first document matching the filter"""
        from mongoframes.queries import Condition, Group, to_refs

        # Flatten the projection
        kwargs['projection'], references, subs = \
                cls._flatten_projection(
                    kwargs.get('projection', cls._default_projection)
                    )

        # Find the document
        if isinstance(filter, (Condition, Group)):
            filter = filter.to_dict()

        document = cls.get_collection().find_one(to_refs(filter), **kwargs)

        # Make sure we found a document
        if not document:
            return

        # Dereference the document (if required)
        if references:
            cls._dereference([document], references)

        # Add sub-frames to the document (if required)
        if subs:
            cls._apply_sub_frames([document], subs)

        return cls(document)
Return the first document matching the filter
Return the first document matching the filter
Return the first document matching the filter
def one(cls, filter=None, **kwargs):
        from mongoframes.queries import Condition, Group, to_refs
        kwargs['projection'], references, subs = \
                cls._flatten_projection(
                    kwargs.get('projection', cls._default_projection)
                    )
        if isinstance(filter, (Condition, Group)):
            filter = filter.to_dict()
        document = cls.get_collection().find_one(to_refs(filter), **kwargs)
        if not document:
            return
        if references:
            cls._dereference([document], references)
        if subs:
            cls._apply_sub_frames([document], subs)
        return cls(document)
def one ( cls , filter = None , ** kwargs ) : from mongoframes . queries import Condition , Group , to_refs kwargs [ 'projection' ] , references , subs = cls . _flatten_projection ( kwargs . get ( 'projection' , cls . _default_projection ) ) if isinstance ( filter , ( Condition , Group ) ) : filter = filter . to_dict ( ) document = cls . get_collection ( ) . find_one ( to_refs ( filter ) , ** kwargs ) if not document : return if references : cls . _dereference ( [ document ] , references ) if subs : cls . _apply_sub_frames ( [ document ] , subs ) return cls ( document )
Return the first document matching the filter
Return the first document matching the filter
"""Return the first document matching the filter""" # Flatten the projection # Find the document # Make sure we found a document # Dereference the document (if required) # Add sub-frames to the document (if required)
cls
filter