pymongo_formatter/formatter.py
def select_fields(doc, field_list):
        '''
        Take 'doc' and create a new doc using only keys from the 'fields' list.
        Supports referencing fields using dotted notation "a.b.c" so we can parse
        nested fields the way MongoDB does. The nested field class is a hack. It should
        be a sub-class of dict.
        '''

        if field_list is None or len(field_list) == 0:
            return doc

        newDoc = Nested_Dict({})
        oldDoc = Nested_Dict(doc)

        for i in field_list:
            if oldDoc.has_key(i):
                # print( "doc: %s" % doc )
                # print( "i: %s" %i )
                newDoc.set_value(i, oldDoc.get_value(i))
        return newDoc.dict_value()
def select_fields(doc, field_list):
        '''
        Take 'doc' and create a new doc using only keys from the 'fields' list.
        Supports referencing fields using dotted notation "a.b.c" so we can parse
        nested fields the way MongoDB does. The nested field class is a hack. It should
        be a sub-class of dict.
        '''

        if field_list is None or len(field_list) == 0:
            return doc

        newDoc = Nested_Dict({})
        oldDoc = Nested_Dict(doc)

        for i in field_list:
            if oldDoc.has_key(i):
                # print( "doc: %s" % doc )
                # print( "i: %s" %i )
                newDoc.set_value(i, oldDoc.get_value(i))
        return newDoc.dict_value()
def select_fields ( doc , field_list ) : if field_list is None or len ( field_list ) == 0 : return doc newDoc = Nested_Dict ( { } ) oldDoc = Nested_Dict ( doc ) for i in field_list : if oldDoc . has_key ( i ) : # print( "doc: %s" % doc ) # print( "i: %s" %i ) newDoc . set_value ( i , oldDoc . get_value ( i ) ) return newDoc . dict_value ( )
Take 'doc' and create a new doc using only keys from the 'fields' list.
        Supports referencing fields using dotted notation "a.b.c" so we can parse
        nested fields the way MongoDB does. The nested field class is a hack. It should
        be a sub-class of dict.
Take doc and create a new doc using only keys from the fields list . Supports referencing fields using dotted notation a . b . c so we can parse nested fields the way MongoDB does . The nested field class is a hack . It should be a sub - class of dict .