def populate(self, blueprint, documents):
        """Populate the database with documents"""

        # Finish the documents
        documents = self.finish(blueprint, documents)

        # Convert the documents to frame instances
        frames = []
        for document in documents:
            # Separate out any meta fields
            meta_document = {}
            for field_name in blueprint._meta_fields:
                meta_document[field_name] = document[field_name]
                document.pop(field_name)

            # Initialize the frame
            frame = blueprint.get_frame_cls()(document)

            # Apply any meta fields
            for key, value in meta_document.items():
                setattr(frame, key, value)

            frames.append(frame)

        # Insert the documents
        blueprint.on_fake(frames)
        frames = blueprint.get_frame_cls().insert_many(frames)
        blueprint.on_faked(frames)

        return frames
def populate ( self , blueprint , documents ) : documents = self . finish ( blueprint , documents ) frames = [ ] for document in documents : meta_document = { } for field_name in blueprint . _meta_fields : meta_document [ field_name ] = document [ field_name ] document . pop ( field_name ) frame = blueprint . get_frame_cls ( ) ( document ) for key , value in meta_document . items ( ) : setattr ( frame , key , value ) frames . append ( frame ) blueprint . on_fake ( frames ) frames = blueprint . get_frame_cls ( ) . insert_many ( frames ) blueprint . on_faked ( frames ) return frames
Populate the database with documents